Permalink
Browse files

Fix SI-5626.

By not replacing 'CaseClass.apply()' factor by 'new CaseClass()' when the class type 'CaseClass' is not accessible.
  • Loading branch information...
lrytz committed May 11, 2012
1 parent 2422b06 commit 0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5
Showing with 29 additions and 2 deletions.
  1. +17 −2 src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
  2. +12 −0 test/files/pos/t5626.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
View
@@ -0,0 +1,12 @@
+class C {
+ val blob = {
+ new { case class Foo() }
+ }
+ val blub = {
+ class Inner { case class Foo() }
+ new Inner
+ }
+
+ val foo = blob.Foo()
+ val bar = blub.Foo()
+}

0 comments on commit 0c5de3c

Please sign in to comment.