diff options
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 11 | ||||
-rw-r--r-- | tests/pos/desugar.scala | 28 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 0739f08d1..fa664ee08 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -421,10 +421,10 @@ object desugar { /** Main desugaring method */ def apply(tree: Tree)(implicit ctx: Context): Tree = { - /** { label def lname() = rhs; call } + /** { label def lname(): Unit = rhs; call } */ def labelDefAndCall(lname: TermName, rhs: Tree, call: Tree) = { - val ldef = DefDef(Modifiers(Label), lname, Nil, ListOfNil, TypeTree(), rhs) + val ldef = DefDef(Modifiers(Label), lname, Nil, ListOfNil, TypeTree(defn.UnitType), rhs) Block(ldef, call) } @@ -686,6 +686,13 @@ object desugar { } }.withPos(tree.pos) + /** Create a class definition with the same info as this refined type. + * parent { refinements } + * ==> + * class <refinement> extends parent { refinements } + * + * The result is used for validity checking, is thrown away afterwards. + */ def refinedTypeToClass(tree: RefinedTypeTree)(implicit ctx: Context): TypeDef = { val impl = Template(emptyConstructor, tree.tpt :: Nil, EmptyValDef, tree.refinements) TypeDef(Modifiers(), tpnme.REFINE_CLASS, impl) diff --git a/tests/pos/desugar.scala b/tests/pos/desugar.scala index 69e8c8651..cfd695af6 100644 --- a/tests/pos/desugar.scala +++ b/tests/pos/desugar.scala @@ -1,8 +1,9 @@ object desugar { - + // variables var x: Int = 2 var y = x * x + val list = List(1, 2, 3) { var z: Int = y } @@ -44,6 +45,8 @@ object desugar { x :: y :: Nil + val x :: y :: Nil = list + } object fors { @@ -54,6 +57,29 @@ object desugar { for (x <- List(1, 2, 3); y <- 0 to x; if x + y % 2 == 0) yield x * y for (x <- List(1, 2, 3); y = x * x; if x + y % 2 == 0) yield x * y for (x <- List(1, 2, 3); y = x * x; z = x * y; u <- 0 to y) yield x * y * z * u + + for (x <- List(1, 2, 3)) println(x) + for (x <- List(1, 2, 3) if x % 2 == 0) println(x * x) + for (x <- List(1, 2, 3); y <- 0 to x) println(x * y) + for (x <- List(1, 2, 3); y <- 0 to x; if x + y % 2 == 0) println(x * y) + for (x <- List(1, 2, 3); y = x * x; if x + y % 2 == 0) println(x * y) + for (x <- List(1, 2, 3); y = x * x; z = x * y; u <- 0 to y) println(x * y * z * u) + } + + object misc { + 'hello + s"this is a $x + ${x + y} string" + type ~ = Tuple2 + val pair: Int ~ String = 1 -> "abc" + def foo(xs: Int*) = xs.length + foo(list: _*) + println(list: _*) + (list length) + - desugar.x + def bar(x: => Int) = x + (x + y) + 1 + while (x < 10) x += 1 + do x -= 1 while (x > 0) } }
\ No newline at end of file |