summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2012-05-11 13:40:21 +0200
committerLukas Rytz <lukas.rytz@epfl.ch>2012-05-11 18:37:00 +0200
commit0c5de3cf31e11614eb93c6a1ae31b87d01ac7db5 (patch)
treef54f96426e682a66212538dd1efad457bf9074b6
parent2422b064e7a52c04dfb2239fc8e7b9ffbab24251 (diff)
downloadscala-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.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala19
-rw-r--r--test/files/pos/t5626.scala12
2 files changed, 29 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
diff --git a/test/files/pos/t5626.scala b/test/files/pos/t5626.scala
new file mode 100644
index 0000000000..c501dfbe60
--- /dev/null
+++ b/test/files/pos/t5626.scala
@@ -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()
+}