Skip to content

Commit 29565f4

Browse files
committed
wip
1 parent b957394 commit 29565f4

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
6161
type If = tpd.If
6262
type ValDef = tpd.ValDef
6363
type Throw = tpd.Apply
64+
type Labeled = tpd.Labeled
6465
type Return = tpd.Return
6566
type Block = tpd.Block
6667
type Typed = tpd.Typed
@@ -193,6 +194,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
193194
implicit val LabelDefTag: ClassTag[LabelDef] = ClassTag[LabelDef](classOf[LabelDef])
194195
implicit val ValDefTag: ClassTag[ValDef] = ClassTag[ValDef](classOf[ValDef])
195196
implicit val ThrowTag: ClassTag[Throw] = ClassTag[Throw](classOf[Throw])
197+
implicit val LabeledTag: ClassTag[Labeled] = ClassTag[Labeled](classOf[Labeled])
196198
implicit val ReturnTag: ClassTag[Return] = ClassTag[Return](classOf[Return])
197199
implicit val LiteralTag: ClassTag[Literal] = ClassTag[Literal](classOf[Literal])
198200
implicit val BlockTag: ClassTag[Block] = ClassTag[Block](classOf[Block])
@@ -1076,8 +1078,14 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10761078
def apply(s: Symbol): This = tpd.This(s.asClass)
10771079
}
10781080

1081+
object Labeled extends LabeledDeconstructor {
1082+
def _1: Bind = field.bind
1083+
def _2: Tree = field.expr
1084+
}
1085+
10791086
object Return extends ReturnDeconstructor {
1080-
def get = field.expr
1087+
def _1: Tree = field.expr
1088+
def _2: Symbol = if (field.from.symbol.isLabel) field.from.symbol else NoSymbol
10811089
}
10821090

10831091
object Ident extends IdentDeconstructor {

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
352352
else changePrec(GlobalPrec) { toText(sel) ~ keywordStr(" match ") ~ blockText(cases) }
353353
case CaseDef(pat, guard, body) =>
354354
keywordStr("case ") ~ inPattern(toText(pat)) ~ optText(guard)(keywordStr(" if ") ~ _) ~ " => " ~ caseBlockText(body)
355+
case Labeled(bind, expr) =>
356+
changePrec(GlobalPrec) { toText(bind.name) ~ keywordStr("[") ~ toText(bind.symbol.info) ~ keywordStr("]: ") ~ toText(expr) }
355357
case Return(expr, from) =>
356-
changePrec(GlobalPrec) { keywordStr("return") ~ optText(expr)(" " ~ _) }
358+
val sym = from.symbol
359+
if (sym.is(Label))
360+
changePrec(GlobalPrec) { keywordStr("return@") ~ toText(sym.name) ~ optText(expr)(" " ~ _) }
361+
else
362+
changePrec(GlobalPrec) { keywordStr("return") ~ optText(expr)(" " ~ _) }
357363
case Try(expr, cases, finalizer) =>
358364
changePrec(GlobalPrec) {
359365
keywordStr("try ") ~ toText(expr) ~ optText(cases)(keywordStr(" catch ") ~ _) ~ optText(finalizer)(keywordStr(" finally ") ~ _)

compiler/src/dotty/tools/dotc/transform/NonLocalReturns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import collection.mutable
1111
object NonLocalReturns {
1212
import ast.tpd._
1313
def isNonLocalReturn(ret: Return)(implicit ctx: Context) =
14-
ret.from.symbol != ctx.owner.enclosingMethod || ctx.owner.is(Lazy)
14+
!ret.from.symbol.is(Label) && (ret.from.symbol != ctx.owner.enclosingMethod || ctx.owner.is(Lazy))
1515
}
1616

1717
/** Implement non-local returns using NonLocalReturnControl exceptions.

tests/pos/HelloWorld.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
object HelloWorld {
2-
def main(args: Array[String]): Unit = println("hello world")
2+
def main(args: Array[String]): Unit = {
3+
println("hello world")
4+
val list = List(1, 2, 3)
5+
list match {
6+
case head :: tail => println(head)
7+
case Nil => println("empty")
8+
}
9+
val s = list match {
10+
case head :: tail => head.toString
11+
case Nil => "empty"
12+
}
13+
println(s)
14+
}
315
}

0 commit comments

Comments
 (0)