Skip to content

Commit 6299833

Browse files
committed
Do not crash when typing a closure with unknown type, since it can occur for erroneous input
1 parent de2d35c commit 6299833

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ object Parsers {
17251725
case arg =>
17261726
arg
17271727
val args1 = args.mapConserve(sanitize)
1728-
1728+
17291729
if in.isArrow || isPureArrow || erasedArgs.contains(true) then
17301730
functionRest(args)
17311731
else

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ class Namer { typer: Typer =>
11311131
private def exportForwarders(exp: Export, pathMethod: Symbol)(using Context): List[tpd.MemberDef] =
11321132
val buf = new mutable.ListBuffer[tpd.MemberDef]
11331133
val Export(expr, selectors) = exp
1134-
if expr.isEmpty then
1134+
if expr.isEmpty || (selectors.size == 1 && selectors.exists(s => s.imported.name == nme.ERROR)) then
11351135
report.error(em"Export selector must have prefix and `.`", exp.srcPos)
11361136
return Nil
11371137

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

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

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.unlift // error // error // error

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)