Skip to content

Commit b3f9eb8

Browse files
committed
Survive unexpected function types after errors are reported.
If errors were already reported, the types function cannot be guaranteed to be TermRefs anymore.
1 parent abb9a5f commit b3f9eb8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,10 @@ trait Applications extends Compatibility {
987987

988988
/** Overridden in ReTyper to handle primitive operations that can be generated after erasure */
989989
protected def handleUnexpectedFunType(tree: untpd.Apply, fun: Tree)(implicit ctx: Context): Tree =
990-
throw new Error(i"unexpected type.\n fun = $fun,\n methPart(fun) = ${methPart(fun)},\n methPart(fun).tpe = ${methPart(fun).tpe},\n tpe = ${fun.tpe}")
990+
if ctx.reporter.errorsReported then
991+
throw TypeError(i"unexpected function type: ${methPart(fun).tpe}")
992+
else
993+
throw Error(i"unexpected type.\n fun = $fun,\n methPart(fun) = ${methPart(fun)},\n methPart(fun).tpe = ${methPart(fun).tpe},\n tpe = ${fun.tpe}")
991994

992995
def typedNamedArgs(args: List[untpd.Tree])(implicit ctx: Context): List[NamedArg] =
993996
for (arg @ NamedArg(id, argtpt) <- args) yield {

tests/neg/i7816.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object A {
2+
def f()(>) = ??? // error
3+
import f.NonExistent // error
4+
}

0 commit comments

Comments
 (0)