Skip to content

Commit 3a5e137

Browse files
authored
Do not crash when typing a closure with unknown type, since it can occur for erroneous input (#21178)
closes #20511
2 parents 64a177f + 6e28679 commit 3a5e137

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,8 +1998,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19981998
// Polymorphic SAMs are not currently supported (#6904).
19991999
EmptyTree
20002000
case tp =>
2001-
if !tp.isErroneous then
2002-
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")
20032001
TypeTree(defn.AnyType)
20042002
}
20052003
else typed(tree.tpt)

tests/neg/i20511-1.check

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- [E083] Type Error: tests/neg/i20511-1.scala:7:7 ---------------------------------------------------------------------
2+
7 |export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error
3+
| ^^^^^^^^^^^^
4+
| Int => Double is not a valid export prefix, since it is not an immutable path
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E083] Type Error: tests/neg/i20511-1.scala:7:27 --------------------------------------------------------------------
8+
7 |export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error
9+
| ^^^^^^^^^^
10+
| Any is not a valid export prefix, since it is not an immutable path
11+
|
12+
| longer explanation available when compiling with `-explain`
13+
-- Error: tests/neg/i20511-1.scala:7:38 --------------------------------------------------------------------------------
14+
7 |export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error
15+
| ^^^^^
16+
| no eligible member apply at {
17+
| def $anonfun(crustType: Double): Double = pakiet.crustPrice(crustType)
18+
| closure(pakiet.$anonfun:Any)
19+
| }
20+
-- [E083] Type Error: tests/neg/i20511-1.scala:7:45 --------------------------------------------------------------------
21+
7 |export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error
22+
| ^^^^^^^^^^
23+
| Any is not a valid export prefix, since it is not an immutable path
24+
|
25+
| longer explanation available when compiling with `-explain`
26+
-- Error: tests/neg/i20511-1.scala:7:56 --------------------------------------------------------------------------------
27+
7 |export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error
28+
| ^^^^^^
29+
| no eligible member unlift at {
30+
| def $anonfun(crustType: Double): Double = pakiet.crustPrice(crustType)
31+
| closure(pakiet.$anonfun:Any)
32+
| }

tests/neg/i20511-1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package pakiet
2+
3+
def toppingPrice(size: Int): Double = ???
4+
5+
def crustPrice(crustType: Double): Double = ???
6+
7+
export toppingPrice.apply, crustPrice.apply, crustPrice.unlift // error // error // error // error // error

tests/neg/i20511.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E040] Syntax Error: tests/neg/i20511.scala:7:19 --------------------------------------------------------------------
2+
7 |export toppingPrice, crustPrice // error // error
3+
| ^
4+
| '.' expected, but ',' found
5+
-- [E040] Syntax Error: tests/neg/i20511.scala:8:0 ---------------------------------------------------------------------
6+
8 |val i = 1 // error
7+
|^^^
8+
|'.' expected, but 'end of statement' found
9+
-- [E083] Type Error: tests/neg/i20511.scala:7:21 ----------------------------------------------------------------------
10+
7 |export toppingPrice, crustPrice // error // error
11+
| ^^^^^^^^^^
12+
| Any is not a valid export prefix, since it is not an immutable path
13+
|
14+
| longer explanation available when compiling with `-explain`

tests/neg/i20511.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package pakiet
2+
3+
def toppingPrice(size: Int): Double = ???
4+
5+
def crustPrice(crustType: Double): Double = ???
6+
7+
export toppingPrice, crustPrice // error // error
8+
val i = 1 // error

0 commit comments

Comments
 (0)