Skip to content

Commit

Permalink
Fixes SI-6758: force LazyAnnnotationInfo for DefDef and TypeDef
Browse files Browse the repository at this point in the history
Looks like the change in 25ecde0 no longer forced
lazy annotations for some of the cases.
Also removed forcing for PackageDef annotations as we currently
don't support them.
  • Loading branch information
hubertp committed Dec 11, 2012
1 parent 7fe7d25 commit 089173d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 32 deletions.
14 changes: 4 additions & 10 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -1929,8 +1929,7 @@ trait Typers extends Modes with Adaptations with Tags {
*/ */
def typedTemplate(templ: Template, parents1: List[Tree]): Template = { def typedTemplate(templ: Template, parents1: List[Tree]): Template = {
val clazz = context.owner val clazz = context.owner
// complete lazy annotations clazz.annotations.map(_.completeInfo)
val annots = clazz.annotations
if (templ.symbol == NoSymbol) if (templ.symbol == NoSymbol)
templ setSymbol clazz.newLocalDummy(templ.pos) templ setSymbol clazz.newLocalDummy(templ.pos)
val self1 = templ.self match { val self1 = templ.self match {
Expand Down Expand Up @@ -2025,8 +2024,7 @@ trait Typers extends Modes with Adaptations with Tags {
val typer1 = constrTyperIf(sym.isParameter && sym.owner.isConstructor) val typer1 = constrTyperIf(sym.isParameter && sym.owner.isConstructor)
val typedMods = typedModifiers(vdef.mods) val typedMods = typedModifiers(vdef.mods)


// complete lazy annotations sym.annotations.map(_.completeInfo)
val annots = sym.annotations
var tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt)) var tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt))
checkNonCyclic(vdef, tpt1) checkNonCyclic(vdef, tpt1)


Expand Down Expand Up @@ -2269,8 +2267,7 @@ trait Typers extends Modes with Adaptations with Tags {
val tparams1 = ddef.tparams mapConserve typedTypeDef val tparams1 = ddef.tparams mapConserve typedTypeDef
val vparamss1 = ddef.vparamss mapConserve (_ mapConserve typedValDef) val vparamss1 = ddef.vparamss mapConserve (_ mapConserve typedValDef)


// complete lazy annotations meth.annotations.map(_.completeInfo)
val annots = meth.annotations


for (vparams1 <- vparamss1; vparam1 <- vparams1 dropRight 1) for (vparams1 <- vparamss1; vparam1 <- vparams1 dropRight 1)
if (isRepeatedParamType(vparam1.symbol.tpe)) if (isRepeatedParamType(vparam1.symbol.tpe))
Expand Down Expand Up @@ -2345,8 +2342,7 @@ trait Typers extends Modes with Adaptations with Tags {
reenterTypeParams(tdef.tparams) reenterTypeParams(tdef.tparams)
val tparams1 = tdef.tparams mapConserve typedTypeDef val tparams1 = tdef.tparams mapConserve typedTypeDef
val typedMods = typedModifiers(tdef.mods) val typedMods = typedModifiers(tdef.mods)
// complete lazy annotations tdef.symbol.annotations.map(_.completeInfo)
val annots = tdef.symbol.annotations


// @specialized should not be pickled when compiling with -no-specialize // @specialized should not be pickled when compiling with -no-specialize
if (settings.nospecialization.value && currentRun.compiles(tdef.symbol)) { if (settings.nospecialization.value && currentRun.compiles(tdef.symbol)) {
Expand Down Expand Up @@ -5253,8 +5249,6 @@ trait Typers extends Modes with Adaptations with Tags {
def typedPackageDef(pdef: PackageDef) = { def typedPackageDef(pdef: PackageDef) = {
val pid1 = typedQualifier(pdef.pid).asInstanceOf[RefTree] val pid1 = typedQualifier(pdef.pid).asInstanceOf[RefTree]
assert(sym.moduleClass ne NoSymbol, sym) assert(sym.moduleClass ne NoSymbol, sym)
// complete lazy annotations
val annots = sym.annotations
val stats1 = newTyper(context.make(tree, sym.moduleClass, sym.info.decls)) val stats1 = newTyper(context.make(tree, sym.moduleClass, sym.info.decls))
.typedStats(pdef.stats, NoSymbol) .typedStats(pdef.stats, NoSymbol)
treeCopy.PackageDef(tree, pid1, stats1) setType NoType treeCopy.PackageDef(tree, pid1, stats1) setType NoType
Expand Down
5 changes: 5 additions & 0 deletions src/reflect/scala/reflect/internal/AnnotationInfos.scala
Expand Up @@ -201,6 +201,8 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
override def toString = if (forced) forcedInfo.toString else "@<?>" override def toString = if (forced) forcedInfo.toString else "@<?>"


override def pos: Position = if (forced) forcedInfo.pos else NoPosition override def pos: Position = if (forced) forcedInfo.pos else NoPosition

override def completeInfo(): Unit = forcedInfo
} }


/** Typed information about an annotation. It can be attached to either /** Typed information about an annotation. It can be attached to either
Expand Down Expand Up @@ -242,6 +244,9 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
this this
} }


// Forces LazyAnnotationInfo, no op otherwise
def completeInfo(): Unit = ()

/** Annotations annotating annotations are confusing so I drew /** Annotations annotating annotations are confusing so I drew
* an example. Given the following code: * an example. Given the following code:
* *
Expand Down
14 changes: 10 additions & 4 deletions test/files/neg/t3222.check
@@ -1,7 +1,13 @@
t3222.scala:4: error: not found: type D
def foo(@throws(classOf[D]) x: Int) {}
^
t3222.scala:1: error: not found: type B t3222.scala:1: error: not found: type B
@throws(classOf[B]) @throws(classOf[B])
^ ^
two errors found t3222.scala:4: error: not found: type D
def foo(@throws(classOf[D]) x: Int) {}
^
t3222.scala:3: error: not found: type C
@throws(classOf[C])
^
t3222.scala:6: error: not found: type E
@throws(classOf[E])
^
four errors found
6 changes: 3 additions & 3 deletions test/files/neg/t6558.check
@@ -1,10 +1,10 @@
t6558.scala:19: error: not found: type classs t6558.scala:4: error: not found: type classs
@classs @classs
^ ^
t6558.scala:22: error: not found: type typeparam t6558.scala:7: error: not found: type typeparam
class D[@typeparam T] class D[@typeparam T]
^ ^
t6558.scala:25: error: not found: type valueparam t6558.scala:10: error: not found: type valueparam
@valueparam x: Any @valueparam x: Any
^ ^
three errors found three errors found
15 changes: 0 additions & 15 deletions test/files/neg/t6558.scala
@@ -1,21 +1,6 @@
class AnnotNotFound { class AnnotNotFound {
def foo(a: Any) = () def foo(a: Any) = ()


foo {
// Not yet issued in the context of this file, see SI-6758
// This error is issued in t6558b.scala
@inargument
def foo = 0
foo
}

() => {
// As per above
@infunction
def foo = 0
()
}

@classs @classs
class C class C


Expand Down
28 changes: 28 additions & 0 deletions test/files/neg/t6758.check
@@ -0,0 +1,28 @@
t6758.scala:5: error: not found: type inargument
@inargument
^
t6758.scala:11: error: not found: type infunction
@infunction
^
t6758.scala:18: error: not found: type nested
@nested
^
t6758.scala:25: error: not found: type param
def func(@param x: Int): Int = 0
^
t6758.scala:28: error: not found: type typealias
@typealias
^
t6758.scala:32: error: not found: type classs
@classs
^
t6758.scala:35: error: not found: type module
@module
^
t6758.scala:38: error: not found: type typeparam
class D[@typeparam T]
^
t6758.scala:41: error: not found: type valueparam
@valueparam x: Any
^
9 errors found
43 changes: 43 additions & 0 deletions test/files/neg/t6758.scala
@@ -0,0 +1,43 @@
class AnnotNotFound {
def foo(a: Any) = ()

foo {
@inargument
def foo = 0
foo
}

() => {
@infunction
def foo = 0
()
}

() => {
val bar: Int = {
@nested
val bar2: Int = 2
2
}
()
}

def func(@param x: Int): Int = 0

abstract class A {
@typealias
type B = Int
}

@classs
class C

@module
object D

class D[@typeparam T]

class E(
@valueparam x: Any
)
}

0 comments on commit 089173d

Please sign in to comment.