@@ -649,8 +649,13 @@ object SpaceEngine {
649
649
// <== refineUsingParent(NatT, class Succ, []) = Succ[NatT]
650
650
// <== isSub(Succ[NatT] <:< Succ[Succ[<?>]]) = false
651
651
def getAppliedClass (tp : Type ): Type = tp match
652
+ case tp @ AppliedType (tycon : TypeRef , _) if tycon.symbol.isClass =>
653
+ // apply arguments if they contain Nothing,
654
+ // because it may affect further selection of children of the class
655
+ val argsNotContainsNothing = tp.args.forall(_.classSymbol != defn.NothingClass )
656
+ if argsNotContainsNothing then tp
657
+ else getAppliedClass(tycon.superType.applyIfParameterized(tp.args))
652
658
case tp @ AppliedType (_ : HKTypeLambda , _) => tp
653
- case tp @ AppliedType (tycon : TypeRef , _) if tycon.symbol.isClass => tp
654
659
case tp @ AppliedType (tycon : TypeProxy , _) => getAppliedClass(tycon.superType.applyIfParameterized(tp.args))
655
660
case tp => tp
656
661
val tp = getAppliedClass(tpOriginal)
@@ -660,7 +665,11 @@ object SpaceEngine {
660
665
else if tp.classSymbol == defn.TupleClass || tp.classSymbol == defn.NonEmptyTupleClass then
661
666
List (child) // TupleN and TupleXXL classes are used for Tuple, but they aren't Tuple's children
662
667
else if (child.is(Private ) || child.is(Sealed )) && child.isOneOf(AbstractOrTrait ) then getChildren(child)
663
- else List (child)
668
+ else
669
+ // if a class contains a field of type Nothing,
670
+ // then it can be ignored in pattern matching, because it is impossible to obtain an instance of it
671
+ val noFieldsWithTypeNothing = child.typeRef.fields.forall(_.symbol.typeRef.classSymbol != defn.NothingClass )
672
+ if noFieldsWithTypeNothing then List (child) else Nil
664
673
}
665
674
val children = trace(i " getChildren( $tp) " )(getChildren(tp.classSymbol))
666
675
0 commit comments