Skip to content

Commit 5b498a2

Browse files
committed
Merge pull request scala#1660 from scalamacros/topic/6023
SI-6023 reify abstract vals
2 parents a0e642b + 548a54d commit 5b498a2

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ trait MethodSynthesis {
426426
// spot that brand of them. In other words it's an artifact of the implementation.
427427
val tpt = derivedSym.tpe.finalResultType match {
428428
case ExistentialType(_, _) => TypeTree()
429+
case _ if mods.isDeferred => TypeTree()
429430
case tp => TypeTree(tp)
430431
}
431432
tpt setPos derivedSym.pos.focus

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5368,8 +5368,14 @@ trait Typers extends Modes with Adaptations with Tags {
53685368
}
53695369

53705370
def typedTypeTree(tree: TypeTree) = {
5371-
if (tree.original != null)
5372-
tree setType typedType(tree.original, mode).tpe
5371+
if (tree.original != null) {
5372+
val newTpt = typedType(tree.original, mode)
5373+
tree setType newTpt.tpe
5374+
newTpt match {
5375+
case tt @ TypeTree() => tree setOriginal tt.original
5376+
case _ => tree
5377+
}
5378+
}
53735379
else
53745380
// we should get here only when something before failed
53755381
// and we try again (@see tryTypedApply). In that case we can assign

test/files/run/t6023.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
abstract trait Foo extends AnyRef {
3+
<stable> <accessor> def a: Int
4+
};
5+
()
6+
}
7+
{
8+
abstract trait Foo extends AnyRef {
9+
<stable> <accessor> def a: Int
10+
};
11+
()
12+
}

test/files/run/t6023.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.reflect.runtime.universe._
2+
import scala.reflect.runtime.{currentMirror => cm}
3+
import scala.tools.reflect.ToolBox
4+
5+
object Test extends App {
6+
// test 1: reify
7+
val tree = reify{ trait Foo { val a: Int } }.tree
8+
println(tree.toString)
9+
10+
// test 2: import and typecheck
11+
val toolbox = cm.mkToolBox()
12+
val ttree = toolbox.typeCheck(tree)
13+
println(ttree.toString)
14+
15+
// test 3: import and compile
16+
toolbox.eval(tree)
17+
}

0 commit comments

Comments
 (0)