Skip to content

Commit 99119ca

Browse files
DarkDimiusodersky
authored andcommitted
Merge pull request scala#1781 from dotty-staging/fix-#1776
Fix scala#1776: Avoid interaction between parameter forwarding and elimByName
2 parents 740ccf8 + 0d266ab commit 99119ca

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
5555
stat match {
5656
case stat: ValDef =>
5757
val sym = stat.symbol.asTerm
58-
if (sym is (ParamAccessor, butNot = Mutable)) {
58+
if (sym.is(ParamAccessor, butNot = Mutable) && !sym.info.isInstanceOf[ExprType]) {
59+
// ElimByName gets confused with methods returning an ExprType,
60+
// so avoid param forwarding if parameter is by name. See i1766.scala
5961
val idx = superArgs.indexWhere(_.symbol == sym)
6062
if (idx >= 0 && superParamNames(idx) == stat.name) { // supercall to like-named parameter
6163
val alias = inheritedAccessor(sym)

tests/pos/i1776.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class X(val y: String)
2+
class Y(y: => String) extends X(y)
3+
class Z(z: => String) extends X(z)

tests/run/implicitFuns.scala

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
object Test {
2+
def main(args: Array[String]) = {
3+
4+
implicit val world: String = "world!"
5+
6+
val i1 = (implicit (s: String) => s.length > 2)
7+
val i2 = {implicit (s: String) => s.length > 2}
8+
9+
assert(i1)
10+
assert(i2)
11+
12+
val x: implicit String => Boolean = { implicit (s: String) => s.length > 2 }
13+
14+
val xx: implicit (String, Int) => Int = implicit (x: String, y: Int) => x.length + y
15+
16+
val y: String => Boolean = x
17+
18+
object nested {
19+
implicit val empty: String = ""
20+
assert(!x)
21+
}
22+
23+
val yy: (String, Int) => Any = xx
24+
25+
val z1: implicit String => Boolean = implicitly[String].length >= 2
26+
assert(z1)
27+
28+
type StringlyBool = implicit String => Boolean
29+
30+
val z2: StringlyBool = implicitly[String].length >= 2
31+
assert(z2)
32+
33+
type Stringly[T] = implicit String => T
34+
35+
val z3: Stringly[Boolean] = implicitly[String].length >= 2
36+
assert(z3)
37+
38+
type GenericImplicit[X] = implicit X => Boolean
39+
40+
val z4: GenericImplicit[String] = implicitly[String].length >= 2
41+
assert(z4)
42+
43+
val b = x("hello")
44+
45+
val b1: Boolean = b
46+
47+
val bi = x
48+
49+
val bi1: Boolean = bi
50+
51+
val c = xx("hh", 22)
52+
53+
val c1: Int = c
54+
}
55+
}

0 commit comments

Comments
 (0)