diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2012-05-11 13:40:21 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2012-05-11 18:37:00 +0200 |
commit | 0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5 (patch) | |
tree | f54f96426e682a66212538dd1efad457bf9074b6 /src | |
parent | 2422b064e7a52c04dfb2239fc8e7b9ffbab24251 (diff) | |
download | scala-0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5.tar.gz scala-0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5.tar.bz2 scala-0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5.zip |
Fix SI-5626.
By not replacing 'CaseClass.apply()' factor by 'new CaseClass()' when the class type 'CaseClass' is not accessible.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index b878ce3a53..4e578e3f0d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1488,8 +1488,23 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R private def transformCaseApply(tree: Tree, ifNot: => Unit) = { val sym = tree.symbol - - if (sym.isSourceMethod && sym.isCase && sym.name == nme.apply) + + def isClassTypeAccessible(tree: Tree): Boolean = tree match { + case TypeApply(fun, targs) => + isClassTypeAccessible(fun) + case Select(module, apply) => + // Fixes SI-5626. Classes in refinement types cannot be constructed with `new`. In this case, + // the companion class is actually not a ClassSymbol, but a reference to an abstract type. + module.symbol.companionClass.isClass + } + + val doTransform = + sym.isSourceMethod && + sym.isCase && + sym.name == nme.apply && + isClassTypeAccessible(tree) + + if (doTransform) toConstructor(tree.pos, tree.tpe) else { ifNot |