Skip to content

Commit 4c84ee8

Browse files
committed
Don't lock in failed callee type typings
When we reach out to get the callee type, we might get an error, e.g. if the callee is overloaded. Example: ``` ch => sb.append(ch) ``` Here we might want to call calleeType to find the argument type of `sb.append` in order to use this type as the type of `ch`. But this fails since `append` is overloaded on StringBuffer. Prevously this did not matter since we called calleeType only as a last effort, so if it failed the whole typing failed. But with the changes forseen for fiing #8111 we need to be able to compute calleeType and retract it if it does not work.
1 parent 5e59f87 commit 4c84ee8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,16 @@ class Typer extends Namer
10131013
case untpd.TypedSplice(expr1) =>
10141014
expr1.tpe
10151015
case _ =>
1016+
given nestedCtx as Context = ctx.fresh.setNewTyperState()
10161017
val protoArgs = args map (_ withType WildcardType)
10171018
val callProto = FunProto(protoArgs, WildcardType)(this, app.isGivenApply)
10181019
val expr1 = typedExpr(expr, callProto)
1019-
fnBody = cpy.Apply(fnBody)(untpd.TypedSplice(expr1), args)
1020-
expr1.tpe
1020+
if nestedCtx.reporter.hasErrors then NoType
1021+
else
1022+
given Context = ctx
1023+
nestedCtx.typerState.commit()
1024+
fnBody = cpy.Apply(fnBody)(untpd.TypedSplice(expr1), args)
1025+
expr1.tpe
10211026
}
10221027
else NoType
10231028
case _ =>

0 commit comments

Comments
 (0)