Downwards comparisons for implicit search and overloading resolution · scala/scala3@340f883 (original) (raw)

`@@ -915,13 +915,54 @@ trait Applications extends Compatibility { self: Typer =>

`

915

915

``

916

916

` {

`

917

917

`implicit val ctx: Context = nestedCtx

`

918

``

`-

isCompatible(tp1, constrained(tp2).resultType)

`

``

918

`+

isAsSpecificValueType(tp1, constrained(tp2).resultType)

`

919

919

` }

`

920

920

`case _ => // (3b)

`

921

``

`-

isCompatible(tp1, tp2)

`

``

921

`+

isAsSpecificValueType(tp1, tp2)

`

922

922

` }

`

923

923

` }}

`

924

924

``

``

925

`` +

/** Test whether value type tp1 is as specific as value type tp2.

``

``

926

`` +

``

``

927

`` +

``

``

928

`` +

``

``

929

`` +

``

``

930

`+

`

``

931

`+

`

``

932

`+

`

``

933

`` +

``

``

934

`` +

``

``

935

`+

`

``

936

`+

`

``

937

`+

`

``

938

`+

`

``

939

`` +

``

``

940

`+

`

``

941

`` +

``

``

942

`+

`

``

943

`+

`

``

944

`` +

``

``

945

`+

`

``

946

`+

`

``

947

`+

`

``

948

`+

`

``

949

`+

`

``

950

`+

`

``

951

`+

*/

`

``

952

`+

def isAsSpecificValueType(tp1: Type, tp2: Type)(implicit ctx: Context) =

`

``

953

`+

if (ctx.mode.is(Mode.OldOverloadingResolution))

`

``

954

`+

isCompatible(tp1, tp2)

`

``

955

`+

else {

`

``

956

`+

val flip = new TypeMap {

`

``

957

`+

def apply(t: Type) = t match {

`

``

958

`+

case t: TypeAlias if variance > 0 && t.variance < 0 => t.derivedTypeAlias(t.alias, 1)

`

``

959

`+

case t: TypeBounds => t

`

``

960

`+

case _ => mapOver(t)

`

``

961

`+

}

`

``

962

`+

}

`

``

963

`+

isCompatible(flip(tp1), flip(tp2))

`

``

964

`+

}

`

``

965

+

925

966

`/** Drop any implicit parameter section */

`

926

967

`def stripImplicit(tp: Type): Type = tp match {

`

927

968

`case mt: ImplicitMethodType if !mt.isDependent =>

`