Skip to content

Commit d46519d

Browse files
committed
Merge pull request scala#2888 from xeno-by/topic/typed-annotated
typedAnnotated no longer emits nulls
2 parents 068b9a3 + 9772ec8 commit d46519d

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4107,7 +4107,7 @@ trait Typers extends Modes with Adaptations with Tags {
41074107
// we need symbol-ful originals for reification
41084108
// hence we go the extra mile to hand-craft tis guy
41094109
val original = arg1 match {
4110-
case tt @ TypeTree() => Annotated(ann, tt.original)
4110+
case tt @ TypeTree() if tt.original != null => Annotated(ann, tt.original)
41114111
// this clause is needed to correctly compile stuff like "new C @D" or "@(inline @getter)"
41124112
case _ => Annotated(ann, arg1)
41134113
}

test/files/run/typed-annotated.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.reflect.macros.Context
2+
import language.experimental.macros
3+
4+
class ann extends scala.annotation.StaticAnnotation
5+
6+
object Macros {
7+
def impl(c: Context) = {
8+
import c.universe._
9+
// val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), Ident(newTypeName("Int")))
10+
val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), TypeTree(weakTypeOf[Int]))
11+
c.Expr[Unit](Block(
12+
List(ValDef(Modifiers(), newTermName("x"), tpt, Literal(Constant(42)))),
13+
Apply(Ident(newTermName("println")), List(Ident(newTermName("x"))))))
14+
}
15+
16+
def foo = macro impl
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Macros.foo
3+
}

0 commit comments

Comments
 (0)