Skip to content

Commit c538739

Browse files
committed
Optimize wildcardArgOK with early wildcard check
Use `hasWildcardArg` to quickly check if the argument type contains wildcard type arguments before performing expensive pattern matching and type comparisons.
1 parent c8d49c9 commit c538739

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,13 +894,15 @@ trait Applications extends Compatibility {
894894
// Class[? <: T] "applicable" where Class[T] is expected by checking if the
895895
// wildcard's upper bound is a subtype of the formal type parameter.
896896
def wildcardArgOK =
897-
(argtpe, formal) match
898-
case (AppliedType(tycon1, args1), AppliedType(tycon2, args2))
899-
if tycon1 =:= tycon2 && args1.length == args2.length =>
900-
args1.lazyZip(args2).forall {
901-
case (TypeBounds(_, hi), formal) => hi relaxed_<:< formal
902-
case (arg, formal) => arg =:= formal
903-
}
897+
argtpe match
898+
case at @ AppliedType(tycon1, args1) if at.hasWildcardArg =>
899+
formal match
900+
case AppliedType(tycon2, args2)
901+
if tycon1 =:= tycon2 && args1.length == args2.length =>
902+
args1.lazyZip(args2).forall {
903+
case (TypeBounds(_, hi), formal) => hi relaxed_<:< formal
904+
}
905+
case _ => false
904906
case _ => false
905907

906908
isCompatible(argtpe, formal) || wildcardArgOK

0 commit comments

Comments
 (0)