Skip to content

Avoid unnecessary under-constrained implicit searches #14353

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

Merged
merged 1 commit into from
Jan 26, 2022
Merged
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
19 changes: 11 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,18 @@ trait Applications extends Compatibility {

protected def init(): Unit = methType match {
case methType: MethodType =>
// apply the result type constraint, unless method type is dependent
val resultApprox = resultTypeApprox(methType)
if (!constrainResult(methRef.symbol, resultApprox, resultType))
if (ctx.typerState.isCommittable)
// defer the problem until after the application;
// it might be healed by an implicit conversion
()
else
fail(TypeMismatch(methType.resultType, resultType, None))
val sym = methRef.symbol
if ctx.typerState.isCommittable then
// Here we call `resultType` only to accumulate constraints (even if
// it fails, we might be able to heal the expression to conform to the
// result type) so don't check for views since `viewExists` doesn't
// have any side-effect and would only slow the compiler down (cf #14333).
NoViewsAllowed.constrainResult(sym, resultApprox, resultType)
else if !constrainResult(sym, resultApprox, resultType) then
// Here we actually record that this alternative failed so that
// overloading resolution might prune it.
fail(TypeMismatch(methType.resultType, resultType, None))

// match all arguments with corresponding formal parameters
matchArgs(orderedArgs, methType.paramInfos, 0)
Expand Down