Skip to content

Fix #18763: Run type inference before implicit search #23020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4250,13 +4250,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else formals1
implicitArgs(formals2, argIndex + 1, pt)

val ownedVars = ctx.typerState.ownedVars
val pt1 = pt.deepenProtoTrans
if ((!formal.isGround) && (formal.simplified `ne` formal) && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && !ownedVars.isEmpty) {
val qualifying = (ownedVars -- locked).toList
if (qualifying.nonEmpty) {
val resultAlreadyConstrained = pt1.isInstanceOf[MethodOrPoly]
if (!resultAlreadyConstrained) {
if ctx.typerState.isCommittable then
NoViewsAllowed.constrainResult(tree.symbol, wtp, pt1)
else constrainResult(tree.symbol, wtp, pt1)
}
}
}
val arg = inferImplicitArg(formal, tree.span.endPos)
arg.tpe match
case failed: AmbiguousImplicits =>
val pt1 = pt.deepenProtoTrans
if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
then implicitArgs(formals, argIndex, pt1)
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
then implicitArgs(formals, argIndex, pt)
else arg :: implicitArgs(formals1, argIndex + 1, pt)
case failed: SearchFailureType =>
lazy val defaultArg = findDefaultArgument(argIndex)
.showing(i"default argument: for $formal, $tree, $argIndex = $result", typr)
Expand Down
Loading