diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-01-30 11:06:55 -0800 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-01-30 11:06:55 -0800 |
commit | fefe6ccc0c47d202156e5e1fc3385b92cbb589a5 (patch) | |
tree | 1dc1de0f5a414816f5790d3b77543e43c56ce803 /src/compiler | |
parent | e22d801a539f951422e91519844c7cb9ce81b413 (diff) | |
download | scala-fefe6ccc0c47d202156e5e1fc3385b92cbb589a5.tar.gz scala-fefe6ccc0c47d202156e5e1fc3385b92cbb589a5.tar.bz2 scala-fefe6ccc0c47d202156e5e1fc3385b92cbb589a5.zip |
SI-7009: `@throws` annotation synthesized incorrectly
The 990b3c7 made `scala.throws` annotation polymorphic but forgot to
adapt compiler code that synthesizes it, e.g. when parsing class files.
The consequence was that we would get non-deterministically either
`scala.throws` or `scala.throws[T]` as a type for synthesized annotation.
The reason is that `Symbol.addAnnotation` would call `tpe` method which
does not initialization of symbol so type parameters list would not be
determined correctly. Only if info of that symbol was forced for other
reason we would get `scala.throws[T]`. That non-deterministic behavior
was observed in sbt's incremental compiler.
Another problem we have is that Scala allows polymorphic exceptions
so in ClassfileParser we could synthesize `@throws` annotation with
wrong (polymorphic) type applied. In such case the best we can do
is to convert such type to monomorphic one by introducing existentials.
Here's list of changes this commit introduces:
* The `Symbol.addAnnotation` that takes symbol as argument asserts
that the type represented by that symbol is monomorphic (disabled
due to cycles; see comments in the code)
* Introduce `Symbol.addAnnotation` overload that allows us to pass
an applied type
* Change all places where polymorphic annotations are synthesized
to pass an applied type
* Handle polymorphic exception types in
`ClassfileParser.parseExceptions`
Fixes SI-7009.
Diffstat (limited to 'src/compiler')
3 files changed, 9 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index d185ed0c34..0abbe44b02 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -1018,7 +1018,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { if (needsAnnotation) { val c = Constant(RemoteExceptionClass.tpe) val arg = Literal(c) setType c.tpe - meth.addAnnotation(ThrowsClass, arg) + meth.addAnnotation(appliedType(ThrowsClass, c.tpe), arg) } } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index fe0020e074..598965b982 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -888,7 +888,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with if (needsAnnotation) { val c = Constant(RemoteExceptionClass.tpe) val arg = Literal(c) setType c.tpe - meth.addAnnotation(ThrowsClass, arg) + meth.addAnnotation(appliedType(ThrowsClass, c.tpe), arg) } } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index a708a262e7..4b1d3c34f3 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -1043,7 +1043,13 @@ abstract class ClassfileParser { val nClasses = in.nextChar for (n <- 0 until nClasses) { val cls = pool.getClassSymbol(in.nextChar.toInt) - sym.addAnnotation(definitions.ThrowsClass, Literal(Constant(cls.tpe))) + val tp = if (cls.isMonomorphicType) cls.tpe else { + debuglog(s"Encountered polymorphic exception `${cls.fullName}` while parsing class file.") + // in case we encounter polymorphic exception the best we can do is to convert that type to + // monomorphic one by introducing existientals, see SI-7009 for details + typer.packSymbols(cls.typeParams, cls.tpe) + } + sym.addAnnotation(appliedType(definitions.ThrowsClass, tp), Literal(Constant(tp))) } } |