summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-12-05 10:18:53 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-01-26 15:39:05 +0100
commit61f29368fecf620585c8bb26bb83c746cbbe6571 (patch)
treec29ddd4f8b17551960f17ca97465bae1ade6e765
parentf01af109ae975461fe5a3120a69814521968fcce (diff)
downloadscala-61f29368fecf620585c8bb26bb83c746cbbe6571.tar.gz
scala-61f29368fecf620585c8bb26bb83c746cbbe6571.tar.bz2
scala-61f29368fecf620585c8bb26bb83c746cbbe6571.zip
SI-4859 Don't rewrite CC().CC2() to new CC2
Where CC and CC2 are case classes. Attempting to do so leads to a "no legal prefix" error. Now, we restrict this optimization (living in RefChecks ?!) to case class applies with a "safe to inline" qualifier.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala9
-rw-r--r--test/files/pos/t4859.scala (renamed from test/pending/pos/t4859.scala)2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index e88447c46d..f0ced1a8d4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1389,9 +1389,12 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
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
+ ( // SI-4859 `CaseClass1().InnerCaseClass2()` must not be rewritten to `new InnerCaseClass2()`
+ treeInfo.isExprSafeToInline(module) &&
+ // 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 =
diff --git a/test/pending/pos/t4859.scala b/test/files/pos/t4859.scala
index ec5abd966d..284a39b7ab 100644
--- a/test/pending/pos/t4859.scala
+++ b/test/files/pos/t4859.scala
@@ -1,5 +1,7 @@
object O {
+ // error: C is not a legal prefix for a constructor
C().CC()
+ // but this works.
D().DD()
}