From f332dcc73e1a644be87b2017201e8a28792c5ef6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 11 Dec 2016 12:31:29 +0100 Subject: [PATCH 1/2] Fix #1776: Avoid interaction between parameter forwarding and elimByName Parameter forwarding is not geared to handle parameters of by-name types correctly and consequently elimByName generates wrong code. Since it's a corner case it's easiest by not applying the parameter forwarding optimization to by-name parameters. --- compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index 9571c387bfc9..a72e10681f45 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -55,7 +55,9 @@ class ParamForwarding(thisTransformer: DenotTransformer) { stat match { case stat: ValDef => val sym = stat.symbol.asTerm - if (sym is (ParamAccessor, butNot = Mutable)) { + if (sym.is(ParamAccessor, butNot = Mutable) && !sym.info.isInstanceOf[ExprType]) { + // ElimByName gets confused with methods returning an ExprType, + // so avoid param forwarding if parameter is by name. See i1766.scala val idx = superArgs.indexWhere(_.symbol == sym) if (idx >= 0 && superParamNames(idx) == stat.name) { // supercall to like-named parameter val alias = inheritedAccessor(sym) From 0d266ab909136c0bead951709a29958fede43408 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 12 Dec 2016 09:43:38 +0100 Subject: [PATCH 2/2] Add test case --- tests/pos/i1776.scala | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/pos/i1776.scala diff --git a/tests/pos/i1776.scala b/tests/pos/i1776.scala new file mode 100644 index 000000000000..265ded0d8403 --- /dev/null +++ b/tests/pos/i1776.scala @@ -0,0 +1,3 @@ +class X(val y: String) +class Y(y: => String) extends X(y) +class Z(z: => String) extends X(z)