From 0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Fri, 11 May 2012 13:40:21 +0200 Subject: Fix SI-5626. By not replacing 'CaseClass.apply()' factor by 'new CaseClass()' when the class type 'CaseClass' is not accessible. --- .../scala/tools/nsc/typechecker/RefChecks.scala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/compiler') 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 -- cgit v1.2.3