Skip to content

Commit a027c09

Browse files
committed
Survive erroneous infix operations
Also, more tests
1 parent 1a1e0ae commit a027c09

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,8 @@ class Typer extends Namer
16931693
val defs = new mutable.ListBuffer[Tree]
16941694
def lift(app: Tree): Tree = (app: @unchecked) match {
16951695
case Apply(fn, args) =>
1696-
tpd.cpy.Apply(app)(fn, LiftImpure.liftArgs(defs, fn.tpe, args))
1696+
if (app.tpe.isError) app
1697+
else tpd.cpy.Apply(app)(fn, LiftImpure.liftArgs(defs, fn.tpe, args))
16971698
case Assign(lhs, rhs) =>
16981699
tpd.cpy.Assign(app)(lhs, lift(rhs))
16991700
case Block(stats, expr) =>

tests/neg/i2808.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C {}
2+
3+
object Test {
4+
def foo1() = { println("foo1") ; 5 }
5+
val c = new C
6+
foo1() m1_: c // error
7+
}

tests/run/i2808.scala

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
class C {
22
def m1_:(f: Int) = ()
33
def m2_:(f: => Int) = ()
4+
def m3_:(f: Int)(implicit c: C) = ()
5+
def m4_:(f: => Int)(implicit c: C) = ()
6+
47
}
58

69
object Test {
7-
def foo() = { println("foo") ; 5 }
10+
def foo1() = { println("foo1") ; 5 }
11+
def foo2() = { println("foo2") ; 5 }
12+
def foo3() = { println("foo3") ; 5 }
13+
def foo4() = { println("foo4") ; 5 }
814

915
def main(args: Array[String]): Unit = {
10-
val c = new C
11-
foo() m1_: c
12-
foo() m2_: c
16+
implicit val c = new C
17+
foo1() m1_: c // foo1
18+
foo2() m2_: c
19+
foo3() m3_: c // foo3
20+
foo4() m4_: c
21+
22+
def bar() = { println("bar"); c }
23+
foo1() m1_: bar() // foo1
24+
// bar
25+
foo2() m2_: bar() // bar
26+
foo3() m3_: bar() // foo3
27+
// bar
28+
foo4() m4_: bar() // bar
1329
}
1430
}

0 commit comments

Comments
 (0)