Skip to content

Commit 089173d

Browse files
committed
Fixes SI-6758: force LazyAnnnotationInfo for DefDef and TypeDef
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.
1 parent 7fe7d25 commit 089173d

File tree

7 files changed

+93
-32
lines changed

7 files changed

+93
-32
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,8 +1929,7 @@ trait Typers extends Modes with Adaptations with Tags {
19291929
*/
19301930
def typedTemplate(templ: Template, parents1: List[Tree]): Template = {
19311931
val clazz = context.owner
1932-
// complete lazy annotations
1933-
val annots = clazz.annotations
1932+
clazz.annotations.map(_.completeInfo)
19341933
if (templ.symbol == NoSymbol)
19351934
templ setSymbol clazz.newLocalDummy(templ.pos)
19361935
val self1 = templ.self match {
@@ -2025,8 +2024,7 @@ trait Typers extends Modes with Adaptations with Tags {
20252024
val typer1 = constrTyperIf(sym.isParameter && sym.owner.isConstructor)
20262025
val typedMods = typedModifiers(vdef.mods)
20272026

2028-
// complete lazy annotations
2029-
val annots = sym.annotations
2027+
sym.annotations.map(_.completeInfo)
20302028
var tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt))
20312029
checkNonCyclic(vdef, tpt1)
20322030

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

2272-
// complete lazy annotations
2273-
val annots = meth.annotations
2270+
meth.annotations.map(_.completeInfo)
22742271

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

23512347
// @specialized should not be pickled when compiling with -no-specialize
23522348
if (settings.nospecialization.value && currentRun.compiles(tdef.symbol)) {
@@ -5253,8 +5249,6 @@ trait Typers extends Modes with Adaptations with Tags {
52535249
def typedPackageDef(pdef: PackageDef) = {
52545250
val pid1 = typedQualifier(pdef.pid).asInstanceOf[RefTree]
52555251
assert(sym.moduleClass ne NoSymbol, sym)
5256-
// complete lazy annotations
5257-
val annots = sym.annotations
52585252
val stats1 = newTyper(context.make(tree, sym.moduleClass, sym.info.decls))
52595253
.typedStats(pdef.stats, NoSymbol)
52605254
treeCopy.PackageDef(tree, pid1, stats1) setType NoType

src/reflect/scala/reflect/internal/AnnotationInfos.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
201201
override def toString = if (forced) forcedInfo.toString else "@<?>"
202202

203203
override def pos: Position = if (forced) forcedInfo.pos else NoPosition
204+
205+
override def completeInfo(): Unit = forcedInfo
204206
}
205207

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

247+
// Forces LazyAnnotationInfo, no op otherwise
248+
def completeInfo(): Unit = ()
249+
245250
/** Annotations annotating annotations are confusing so I drew
246251
* an example. Given the following code:
247252
*

test/files/neg/t3222.check

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
t3222.scala:4: error: not found: type D
2-
def foo(@throws(classOf[D]) x: Int) {}
3-
^
41
t3222.scala:1: error: not found: type B
52
@throws(classOf[B])
63
^
7-
two errors found
4+
t3222.scala:4: error: not found: type D
5+
def foo(@throws(classOf[D]) x: Int) {}
6+
^
7+
t3222.scala:3: error: not found: type C
8+
@throws(classOf[C])
9+
^
10+
t3222.scala:6: error: not found: type E
11+
@throws(classOf[E])
12+
^
13+
four errors found

test/files/neg/t6558.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
t6558.scala:19: error: not found: type classs
1+
t6558.scala:4: error: not found: type classs
22
@classs
33
^
4-
t6558.scala:22: error: not found: type typeparam
4+
t6558.scala:7: error: not found: type typeparam
55
class D[@typeparam T]
66
^
7-
t6558.scala:25: error: not found: type valueparam
7+
t6558.scala:10: error: not found: type valueparam
88
@valueparam x: Any
99
^
1010
three errors found

test/files/neg/t6558.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
class AnnotNotFound {
22
def foo(a: Any) = ()
33

4-
foo {
5-
// Not yet issued in the context of this file, see SI-6758
6-
// This error is issued in t6558b.scala
7-
@inargument
8-
def foo = 0
9-
foo
10-
}
11-
12-
() => {
13-
// As per above
14-
@infunction
15-
def foo = 0
16-
()
17-
}
18-
194
@classs
205
class C
216

test/files/neg/t6758.check

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
t6758.scala:5: error: not found: type inargument
2+
@inargument
3+
^
4+
t6758.scala:11: error: not found: type infunction
5+
@infunction
6+
^
7+
t6758.scala:18: error: not found: type nested
8+
@nested
9+
^
10+
t6758.scala:25: error: not found: type param
11+
def func(@param x: Int): Int = 0
12+
^
13+
t6758.scala:28: error: not found: type typealias
14+
@typealias
15+
^
16+
t6758.scala:32: error: not found: type classs
17+
@classs
18+
^
19+
t6758.scala:35: error: not found: type module
20+
@module
21+
^
22+
t6758.scala:38: error: not found: type typeparam
23+
class D[@typeparam T]
24+
^
25+
t6758.scala:41: error: not found: type valueparam
26+
@valueparam x: Any
27+
^
28+
9 errors found

test/files/neg/t6758.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class AnnotNotFound {
2+
def foo(a: Any) = ()
3+
4+
foo {
5+
@inargument
6+
def foo = 0
7+
foo
8+
}
9+
10+
() => {
11+
@infunction
12+
def foo = 0
13+
()
14+
}
15+
16+
() => {
17+
val bar: Int = {
18+
@nested
19+
val bar2: Int = 2
20+
2
21+
}
22+
()
23+
}
24+
25+
def func(@param x: Int): Int = 0
26+
27+
abstract class A {
28+
@typealias
29+
type B = Int
30+
}
31+
32+
@classs
33+
class C
34+
35+
@module
36+
object D
37+
38+
class D[@typeparam T]
39+
40+
class E(
41+
@valueparam x: Any
42+
)
43+
}

0 commit comments

Comments
 (0)