Skip to content

Commit 0dca461

Browse files
committed
Revert "Constrain by deepening results in more implicit searches"
This reverts commit a1813d1.
1 parent b63842f commit 0dca461

File tree

4 files changed

+13
-35
lines changed

4 files changed

+13
-35
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
2929

3030
val synthesizedClassTag: SpecialHandler = (formal, span) =>
3131
def instArg(tp: Type): Type = tp.dealias match
32+
// Special case to avoid instantiating `Int & S` to `Int & Nothing` in
33+
// i16328.scala. The intersection comes from an earlier instantiation
34+
// to an upper bound.
35+
// The dual situation with unions is harder to trigger because lower
36+
// bounds are usually widened during instantiation.
3237
case tp: AndOrType if tp.tp1 =:= tp.tp2 =>
33-
// Special case to avoid instantiating `Int & S` to `Int & Nothing` in
34-
// i16328.scala. The intersection comes from an earlier instantiation
35-
// to an upper bound.
36-
// The dual situation with unions is harder to trigger because lower
37-
// bounds are usually widened during instantiation.
3838
instArg(tp.tp1)
3939
case tvar: TypeVar if ctx.typerState.constraint.contains(tvar) =>
4040
// If tvar has a lower or upper bound:

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,23 +3883,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38833883
implicitArgs(formals2, argIndex + 1, pt)
38843884

38853885
val arg = inferImplicitArg(formal, tree.span.endPos)
3886-
3887-
def canProfitFromMoreConstraints =
3888-
arg.tpe.isInstanceOf[AmbiguousImplicits]
3889-
// ambiguity could be decided by more constraints
3890-
|| !isFullyDefined(formal, ForceDegree.none)
3891-
// more context might constrain type variables which could make implicit scope larger
3892-
38933886
arg.tpe match
3894-
case failed: SearchFailureType if canProfitFromMoreConstraints =>
3887+
case failed: AmbiguousImplicits =>
38953888
val pt1 = pt.deepenProtoTrans
38963889
if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
3897-
then return implicitArgs(formals, argIndex, pt1)
3898-
case _ =>
3899-
3900-
arg.tpe match
3901-
case failed: AmbiguousImplicits =>
3902-
arg :: implicitArgs(formals1, argIndex + 1, pt)
3890+
then implicitArgs(formals, argIndex, pt1)
3891+
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
39033892
case failed: SearchFailureType =>
39043893
lazy val defaultArg =
39053894
def appPart(t: Tree): Tree = t match

tests/neg/i9568.check

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
| No given instance of type => Monad[F] was found for parameter ev of method blaMonad in object Test.
55
| I found:
66
|
7-
| Test.blaMonad[F², S]
7+
| Test.blaMonad[F², S](Test.blaMonad[F³, S²])
88
|
9-
| But method blaMonad in object Test does not match type => Monad[F]
9+
| But method blaMonad in object Test does not match type => Monad[F²]
1010
|
1111
| where: F is a type variable with constraint <: [_] =>> Any
1212
| F² is a type variable with constraint <: [_] =>> Any
13+
| F³ is a type variable with constraint <: [_] =>> Any
14+
| S is a type variable
15+
| S² is a type variable
1316
| .

tests/pos/i23526.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)