@@ -740,27 +740,31 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
740
740
741
741
def fromScala2x = unapplyFn.symbol.exists && (unapplyFn.symbol.owner is Scala2x )
742
742
743
- /** Can `subtp` be made to be a subtype of `tp`, possibly by dropping some
744
- * refinements in `tp`?
743
+ /** Is `subtp` a subtype of `tp` or of some generalization of `tp`?
744
+ * The generalizations of a type T are the smallest set G such that
745
+ *
746
+ * - T is in G
747
+ * - If a typeref R in G represents a trait, R's superclass is in G.
748
+ * - If a type proxy P is not a reference to a class, P's supertype is in G
745
749
*/
746
750
def isSubTypeOfParent (subtp : Type , tp : Type )(implicit ctx : Context ): Boolean =
747
751
if (subtp <:< tp) true
748
752
else tp match {
749
- case tp : RefinedType => isSubTypeOfParent(subtp, tp.parent)
753
+ case tp : TypeRef if tp.symbol.isClass =>
754
+ tp.symbol.is(Trait ) && isSubTypeOfParent(subtp, tp.firstParent)
755
+ case tp : TypeProxy => isSubTypeOfParent(subtp, tp.superType)
750
756
case _ => false
751
757
}
752
758
753
759
unapplyFn.tpe.widen match {
754
760
case mt : MethodType if mt.paramTypes.length == 1 =>
755
761
val unapplyArgType = mt.paramTypes.head
756
762
unapp.println(i " unapp arg tpe = $unapplyArgType, pt = $selType" )
757
- def wpt = widenForMatchSelector(selType) // needed?
758
763
val ownType =
759
764
if (selType <:< unapplyArgType) {
760
- // fullyDefinedType(unapplyArgType, "extractor argument", tree.pos)
761
765
unapp.println(i " case 1 $unapplyArgType ${ctx.typerState.constraint}" )
762
766
selType
763
- } else if (isSubTypeOfParent(unapplyArgType, wpt )(ctx.addMode(Mode .GADTflexible ))) {
767
+ } else if (isSubTypeOfParent(unapplyArgType, selType )(ctx.addMode(Mode .GADTflexible ))) {
764
768
maximizeType(unapplyArgType) match {
765
769
case Some (tvar) =>
766
770
def msg =
@@ -786,9 +790,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
786
790
unapplyArgType
787
791
} else {
788
792
unapp.println(" Neither sub nor super" )
789
- unapp.println(TypeComparer .explained(implicit ctx => unapplyArgType <:< wpt ))
793
+ unapp.println(TypeComparer .explained(implicit ctx => unapplyArgType <:< selType ))
790
794
errorType(
791
- d " Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $wpt " ,
795
+ d " Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $selType " ,
792
796
tree.pos)
793
797
}
794
798
0 commit comments