Skip to content

Commit 5d58407

Browse files
committed
Variant: Declare implicit/givens pairs ambiguous for winsType
Since we specialize implicits and generalize givens, it's logical that we can't compare givens and implicits.
1 parent 618fe83 commit 5d58407

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ trait Applications extends Compatibility {
19221922
case _ => mapOver(t)
19231923
(flip(tp1p) relaxed_<:< flip(tp2p)) || viewExists(tp1, tp2)
19241924
else
1925-
if alt1IsImplicit != alt2IsImplicit then alt2IsImplicit
1925+
if alt1IsImplicit != alt2IsImplicit then false // don't know how to compare these
19261926
else (tp2p relaxed_<:< tp1p) || viewExists(tp2, tp1)
19271927
end isAsGoodValueType
19281928

tests/neg/i21212.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- [E172] Type Error: tests/neg/i21212.scala:8:52 ----------------------------------------------------------------------
2+
8 | def test2(using a2: A)(implicit b2: B) = summon[A] // error: ambiguous
3+
| ^
4+
|Ambiguous given instances: both parameter b2 and parameter a2 match type Minimization.A of parameter x of method summon in object Predef

tests/neg/i21212.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
object Minimization:
3+
4+
trait A
5+
trait B extends A
6+
7+
def test1(using a1: A)(using b1: B) = summon[A] // picks (most general) a1
8+
def test2(using a2: A)(implicit b2: B) = summon[A] // error: ambiguous
9+
def test3(implicit a3: A, b3: B) = summon[A] // picks (most specific) b3
10+
11+
end Minimization

tests/pos/i21212.scala

-11
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,3 @@ class UsingArguments[F[_]](using Temporal[F])(using err: MonadError[F, Throwable
2020
val bool: F[Boolean] = ???
2121
def works = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5
2222

23-
24-
object Minimization:
25-
26-
trait A
27-
trait B extends A
28-
29-
def test1(using a1: A)(using b1: B) = summon[A] // picks (most general) a1
30-
def test2(using a2: A)(implicit b2: B) = summon[A] // picks (most general) a2, was ambiguous
31-
def test3(implicit a3: A, b3: B) = summon[A] // picks (most specific) b3
32-
33-
end Minimization

0 commit comments

Comments
 (0)