From ec5cbcc6b93f96755f7b4fa68a86cab845eca2f4 Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Thu, 11 Jul 2024 17:34:44 +0200 Subject: [PATCH] Do not crash when typing a closure with unknown type, since it can occur for erroneous input --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 -- tests/neg/i20511-1.scala | 7 +++++++ tests/neg/i20511.scala | 8 ++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/neg/i20511-1.scala create mode 100644 tests/neg/i20511.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index e28ba5fd669e..ba3f93a42b91 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index dbc9818abf23..f5f974b33c88 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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) diff --git a/tests/neg/i20511-1.scala b/tests/neg/i20511-1.scala new file mode 100644 index 000000000000..03bd475ffafd --- /dev/null +++ b/tests/neg/i20511-1.scala @@ -0,0 +1,7 @@ +package pakiet + +def toppingPrice(size: Int): Double = ??? + +def crustPrice(crustType: Double): Double = ??? + +export toppingPrice.apply, crustPrice.unlift // error // error // error diff --git a/tests/neg/i20511.scala b/tests/neg/i20511.scala new file mode 100644 index 000000000000..657609536bf0 --- /dev/null +++ b/tests/neg/i20511.scala @@ -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