@@ -1831,7 +1831,8 @@ trait Applications extends Compatibility {
1831
1831
}
1832
1832
case _ => // (3)
1833
1833
def compareValues (tp1 : Type , tp2 : Type )(using Context ) =
1834
- isAsGoodValueType(tp1, tp2, alt1.symbol.is(Implicit ), alt2.symbol.is(Implicit ))
1834
+ extension (alt : TermRef ) def isNotGivenClass : Boolean = alt.symbol == defn.NotGivenClass
1835
+ isAsGoodValueType(tp1, tp2, alt1.isNotGivenClass, alt2.isNotGivenClass)
1835
1836
tp2 match
1836
1837
case tp2 : MethodType => true // (3a)
1837
1838
case tp2 : PolyType if tp2.resultType.isInstanceOf [MethodType ] => true // (3a)
@@ -1868,15 +1869,15 @@ trait Applications extends Compatibility {
1868
1869
* for overloading resolution (when `preferGeneral is false), and the opposite relation
1869
1870
* `U <: T` or `U convertible to `T` for implicit disambiguation between givens
1870
1871
* (when `preferGeneral` is true). For old-style implicit values, the 3.4 behavior is kept.
1871
- * If one of the alternatives is an implicit and the other is a given (or an extension), the implicit loses.
1872
+ * If one of the alternatives is a NotGivenClass, and the other is not, then the NotGivenClass loses.
1872
1873
*
1873
1874
* - In Scala 3.5 and Scala 3.6-migration, we issue a warning if the result under
1874
1875
* Scala 3.6 differ wrt to the old behavior up to 3.5.
1875
1876
*
1876
1877
* Also and only for given resolution: If a compared type refers to a given or its module class, use
1877
1878
* the intersection of its parent classes instead.
1878
1879
*/
1879
- def isAsGoodValueType (tp1 : Type , tp2 : Type , alt1IsImplicit : Boolean , alt2IsImplicit : Boolean )(using Context ): Boolean =
1880
+ def isAsGoodValueType (tp1 : Type , tp2 : Type , alt1IsNotGivenClass : Boolean , alt2IsNotGivenClass : Boolean )(using Context ): Boolean =
1880
1881
val oldResolution = ctx.mode.is(Mode .OldImplicitResolution )
1881
1882
if ! preferGeneral || Feature .migrateTo3 && oldResolution then
1882
1883
// Normal specificity test for overloading resolution (where `preferGeneral` is false)
@@ -1892,10 +1893,7 @@ trait Applications extends Compatibility {
1892
1893
val tp1p = prepare(tp1)
1893
1894
val tp2p = prepare(tp2)
1894
1895
1895
- if Feature .sourceVersion.isAtMost(SourceVersion .`3.4`)
1896
- || oldResolution
1897
- || alt1IsImplicit && alt2IsImplicit
1898
- then
1896
+ if Feature .sourceVersion.isAtMost(SourceVersion .`3.4`) || oldResolution then
1899
1897
// Intermediate rules: better means specialize, but map all type arguments downwards
1900
1898
// These are enabled for 3.0-3.5, and for all comparisons between old-style implicits,
1901
1899
// and in 3.5 and 3.6-migration when we compare with previous rules.
@@ -1909,8 +1907,8 @@ trait Applications extends Compatibility {
1909
1907
case _ => mapOver(t)
1910
1908
(flip(tp1p) relaxed_<:< flip(tp2p)) || viewExists(tp1, tp2)
1911
1909
else
1912
- // New rules: better means generalize, givens (and extensions) always beat implicits
1913
- if alt1IsImplicit != alt2IsImplicit then alt2IsImplicit
1910
+ // New rules: better means generalize, except `NotGivenClass` which is given lower priority
1911
+ if alt1IsNotGivenClass != alt2IsNotGivenClass then alt2IsNotGivenClass
1914
1912
else (tp2p relaxed_<:< tp1p) || viewExists(tp2, tp1)
1915
1913
end isAsGoodValueType
1916
1914
0 commit comments