Skip to content

Commit 38be42e

Browse files
authored
Merge pull request #117 from scala/backport-lts-3.3-21178
Backport "Do not crash when typing a closure with unknown type, since it can occur for erroneous input" to 3.3 LTS
2 parents 763f5c2 + 60900bb commit 38be42e

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -1722,8 +1722,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17221722
EmptyTree
17231723
}
17241724
case tp =>
1725-
if !tp.isErroneous then
1726-
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")
17271725
TypeTree(defn.AnyType)
17281726
}
17291727
else typed(tree.tpt)

tests/neg/i20511-1.check

+32
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

+7
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

+14
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

+8
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)