summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-06-18 19:33:06 +0200
committerAleksandar Prokopec <axel22@gmail.com>2012-06-18 19:33:06 +0200
commita83586a4815acd35df0801ed0e9f067e113c8664 (patch)
treef0efc810997d6d4089dadd5c443a00c10a63d09d /src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
parent9a28ee1ffc085bc680c48b12ad632b9133adf020 (diff)
downloadscala-a83586a4815acd35df0801ed0e9f067e113c8664.tar.gz
scala-a83586a4815acd35df0801ed0e9f067e113c8664.tar.bz2
scala-a83586a4815acd35df0801ed0e9f067e113c8664.zip
Fix SI-4541.
Catch type errors when duplicating trees. In this case, to access a protected member from a specialized class is an error, so we would have to make the member public anyway. Better it is then to report an error and have the user make the field public explicitly. Review by @dragos.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 4b488a6437..c4c769d7cf 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -1448,20 +1448,29 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case ddef @ DefDef(_, _, _, vparamss, _, _) if info.isDefinedAt(symbol) =>
// log("--> method: " + ddef + " in " + ddef.symbol.owner + ", " + info(symbol))
+ def reportTypeError(body: =>Tree) =
+ try body
+ catch {
+ case te: TypeError =>
+ reporter.error(te.pos, te.toString)
+ ddef
+ }
if (symbol.isConstructor) {
val t = atOwner(symbol)(forwardCtorCall(tree.pos, gen.mkSuperSelect, vparamss, symbol.owner))
if (symbol.isPrimaryConstructor)
localTyper.typedPos(symbol.pos)(deriveDefDef(tree)(_ => Block(List(t), Literal(Constant()))))
- else // duplicate the original constructor
- duplicateBody(ddef, info(symbol).target)
+ else // duplicate the original constructor
+ reportTypeError(duplicateBody(ddef, info(symbol).target))
}
else info(symbol) match {
case Implementation(target) =>
assert(body.isDefinedAt(target), "sym: " + symbol.fullName + " target: " + target.fullName)
// we have an rhs, specialize it
- val tree1 = duplicateBody(ddef, target)
+ val tree1 = reportTypeError {
+ duplicateBody(ddef, target)
+ }
debuglog("implementation: " + tree1)
deriveDefDef(tree1)(transform)
@@ -1472,7 +1481,9 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
else {
// we have an rhs, specialize it
- val tree1 = duplicateBody(ddef, target)
+ val tree1 = reportTypeError {
+ duplicateBody(ddef, target)
+ }
debuglog("implementation: " + tree1)
deriveDefDef(tree1)(transform)
}