Skip to content

Commit

Permalink
Do not crash when typing a closure with unknown type, since it can oc…
Browse files Browse the repository at this point in the history
…cur for erroneous input
  • Loading branch information
KacperFKorban committed Jul 11, 2024
1 parent de2d35c commit 6299833
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ object Parsers {
case arg =>
arg
val args1 = args.mapConserve(sanitize)

if in.isArrow || isPureArrow || erasedArgs.contains(true) then
functionRest(args)
else
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ class Namer { typer: Typer =>
private def exportForwarders(exp: Export, pathMethod: Symbol)(using Context): List[tpd.MemberDef] =
val buf = new mutable.ListBuffer[tpd.MemberDef]
val Export(expr, selectors) = exp
if expr.isEmpty then
if expr.isEmpty || (selectors.size == 1 && selectors.exists(s => s.imported.name == nme.ERROR)) then
report.error(em"Export selector must have prefix and `.`", exp.srcPos)
return Nil

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1977,8 +1977,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// Polymorphic SAMs are not currently supported (#6904).
EmptyTree
case tp =>
if !tp.isErroneous then
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")
TypeTree(defn.AnyType)
}
else typed(tree.tpt)
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i20511-1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pakiet

def toppingPrice(size: Int): Double = ???

def crustPrice(crustType: Double): Double = ???

export toppingPrice.apply, crustPrice.unlift // error // error // error
8 changes: 8 additions & 0 deletions tests/neg/i20511.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pakiet

def toppingPrice(size: Int): Double = ???

def crustPrice(crustType: Double): Double = ???

export toppingPrice, crustPrice // error // error
val i = 1 // error

0 comments on commit 6299833

Please sign in to comment.