Permalink
Browse files

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.
  • Loading branch information...
retronym committed Dec 5, 2012
1 parent f01af10 commit 61f29368fecf620585c8bb26bb83c746cbbe6571
@@ -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 =
@@ -1,5 +1,7 @@
object O {
+ // error: C is not a legal prefix for a constructor
C().CC()
+ // but this works.
D().DD()
}

0 comments on commit 61f2936

Please sign in to comment.