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 22 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c1f2338
Run type inference before implicit search
Alex1005a Apr 20, 2025
ad5ab27
new typer state when infer types before search implicit
Alex1005a Apr 20, 2025
9be384b
not infer if type not simplified before implicit search
Alex1005a Apr 22, 2025
4fe718b
return constrainResult after AmbiguousImplicits
Alex1005a Apr 24, 2025
9f3c727
run constrainResult before implicit search when search type not ground
Alex1005a Apr 25, 2025
5ec51bc
Approximate result type before constrain
Alex1005a Apr 27, 2025
116fdfc
not subst dummyArg if tree is TypedSlice
Alex1005a Apr 27, 2025
1a8afbc
not constrainResult if type contains Wildcard Types
Alex1005a Apr 28, 2025
77a83c6
move constrain to function
Alex1005a Apr 29, 2025
58993a0
return isGround check
Alex1005a Apr 29, 2025
76d8913
return resultAlreadyConstrained check
Alex1005a Apr 29, 2025
d03d8bd
return simplified check
Alex1005a Apr 29, 2025
23cc07f
fix
Alex1005a Apr 29, 2025
b91ad9b
no need in constrain type, if it already constrained
Alex1005a Apr 29, 2025
480cb8d
subtype check instead constrainResult
Alex1005a May 24, 2025
24b2dc7
remove resultAlreadyConstrained check
Alex1005a May 25, 2025
368095d
Merge branch 'main' into fix-18763
Alex1005a Jul 19, 2025
d94a22f
change isGround
Alex1005a Jul 19, 2025
e8c4c10
use wildApprox instead isGround
Alex1005a Jul 19, 2025
e5b2e76
not constrain if formal contains constrained type vars
Alex1005a Jul 20, 2025
e41045e
not constrain if formal contains instantiated type vars
Alex1005a Jul 20, 2025
3a4aabd
not constrain if formal contains instantiated type vars
Alex1005a Jul 20, 2025
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
20 changes: 19 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4357,6 +4357,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else formals1
implicitArgs(formals2, argIndex + 1, pt)

val pt1 = pt.deepenProtoTrans
val approxPt = withMode(Mode.TypevarsMissContext):
wildApprox(pt1)
var formalConstrained = false
val tm = new TypeMap:
def apply(t: Type): Type = t match
case tvar: TypeVar =>
formalConstrained |= ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar]
tvar
case _ =>
if formalConstrained then t
else mapOver(t)
tm(formal)
if (pt1 `ne` pt)
&& (pt1 ne sharpenedPt)
&& (AvoidWildcardsMap()(approxPt) `eq` approxPt)
&& !isFullyDefined(formal, ForceDegree.none)
&& !formalConstrained then
constrainResult(tree.symbol, wtp, pt1)
val arg = inferImplicitArg(formal, tree.span.endPos)

def canProfitFromMoreConstraints =
Expand All @@ -4367,7 +4386,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

arg.tpe match
case failed: SearchFailureType if canProfitFromMoreConstraints =>
val pt1 = pt.deepenProtoTrans
if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
then return implicitArgs(formals, argIndex, pt1)
case _ =>
Expand Down
Loading