Skip to content

Commit 054065f

Browse files
committed
Try instantiation after implicit conversion
DottyLanguageServer contained an example that shows that we should not instantiate type variables before trying an implicit conversion.
1 parent 67954fe commit 054065f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,25 +2186,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
21862186
}
21872187
case _ =>
21882188
}
2189-
// try to fully instantiate type
2190-
{ val localCtx = ctx.fresh.setNewTyperState
2191-
val prevConstraint = localCtx.typerState.constraint
2192-
if (isFullyDefined(wtp, force = ForceDegree.all)(localCtx) &&
2193-
localCtx.typerState.constraint.ne(prevConstraint)) {
2194-
val tree1 = adapt(tree, pt, original)(localCtx)
2195-
if (!localCtx.reporter.hasErrors) {
2196-
localCtx.typerState.commit()
2197-
return tree1
2198-
}
2199-
}
2200-
}
22012189
// try an implicit conversion
22022190
inferView(tree, pt) match {
22032191
case SearchSuccess(inferred, _, _, _) =>
22042192
adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled))
22052193
case failure: SearchFailure =>
22062194
if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree
2207-
else err.typeMismatch(tree, pt, failure)
2195+
else {
2196+
// try to fully instantiate type
2197+
val nestedCtx = ctx.fresh.setNewTyperState
2198+
val prevConstraint = nestedCtx.typerState.constraint
2199+
if (isFullyDefined(wtp, force = ForceDegree.all)(nestedCtx) &&
2200+
nestedCtx.typerState.constraint.ne(prevConstraint)) {
2201+
nestedCtx.typerState.commit()
2202+
return adapt(tree, pt, original)
2203+
}
2204+
}
2205+
err.typeMismatch(tree, pt, failure)
22082206
}
22092207
}
22102208

0 commit comments

Comments
 (0)