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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
37 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
fe2a943
type fully defined then typevar instantiated to other typevar
Alex1005a Jul 26, 2025
33d98ad
revert
Alex1005a Jul 26, 2025
899c5e6
wildApprox before constrain result
Alex1005a Jul 27, 2025
53563a7
use isFullyDefined
Alex1005a Jul 27, 2025
01c8620
use new ctx in isFullyDefined
Alex1005a Jul 27, 2025
d00a472
Merge branch 'main' into fix-18763
Alex1005a Jul 27, 2025
15ea692
disable implicits
Alex1005a Jul 27, 2025
6d4b65f
remove ctx from funproto derive function
Alex1005a Jul 28, 2025
eb160eb
subst new ctx in funproto
Alex1005a Jul 28, 2025
4356333
subst new ctx in funproto
Alex1005a Jul 28, 2025
111e4a0
use containsWildcardTypes
Alex1005a Jul 29, 2025
9a3b024
not constrain if formal contains instantiated type vars
Alex1005a Aug 17, 2025
f4d87a5
Merge branch 'main' into fix-18763
Alex1005a Aug 17, 2025
6a98e3a
pt1 already exists in scope
Alex1005a Aug 17, 2025
976af59
use TypeAccumulator
Alex1005a Aug 17, 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
17 changes: 16 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4364,6 +4364,22 @@ 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)
val containsUninst = new TypeAccumulator[Boolean]:
def apply(need: Boolean, tp: Type): Boolean =
need || tp.match
case tvar: TypeVar =>
ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar]
case _ =>
foldOver(need, tp)
if (pt1 `ne` pt)
&& (pt1 ne sharpenedPt)
&& (AvoidWildcardsMap()(approxPt) `eq` approxPt)
&& !isFullyDefined(formal, ForceDegree.none)
&& !containsUninst(false, formal) then
constrainResult(tree.symbol, wtp, pt1)
val arg = inferImplicitArg(formal, tree.span.endPos)

lazy val defaultArg = findDefaultArgument(argIndex)
Expand All @@ -4389,7 +4405,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) && tryConstrainResult(pt1) then
return implicitArgs(formals, argIndex, pt1)
case _ =>
Expand Down
Loading