From 79c053738b8907e461e5087f63d247a64271509a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 17 Mar 2015 16:17:04 -0700 Subject: SI-9223 By-name constructor params should not be aliased Usually, the compiler tries avoids creating a field in a subclass for a constructor parameter that is known to be stored in a field in one of its superclasses. However, in the enclosed test `run/t9223.scala`, this mechanism confuses `=> A` with `A`, which results in a runtime `ClassCastException`. This commit avoids using param aliases for by-name parameters. I have also added a test for something close the opposite case, where the subclass has a strict parameter and the superclass has a by-name parameter. This was working correctly before this patch. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3a85d16f55..758425aad5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2053,7 +2053,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper case acc => acc } ownAcc match { - case acc: TermSymbol if !acc.isVariable => + case acc: TermSymbol if !acc.isVariable && !isByNameParamType(acc.info) => debuglog(s"$acc has alias ${alias.fullLocationString}") acc setAlias alias case _ => -- cgit v1.2.3