707 public boolean containedBy(Type t, Type s) { |
707 public boolean containedBy(Type t, Type s) { |
708 switch (t.tag) { |
708 switch (t.tag) { |
709 case UNDETVAR: |
709 case UNDETVAR: |
710 if (s.tag == WILDCARD) { |
710 if (s.tag == WILDCARD) { |
711 UndetVar undetvar = (UndetVar)t; |
711 UndetVar undetvar = (UndetVar)t; |
712 undetvar.inst = glb(upperBound(s), undetvar.inst); |
712 WildcardType wt = (WildcardType)s; |
713 // We should check instantiated type against any of the |
713 switch(wt.kind) { |
714 // undetvar's lower bounds. |
714 case UNBOUND: //similar to ? extends Object |
715 for (Type t2 : undetvar.lobounds) { |
715 case EXTENDS: { |
716 if (!isSubtype(t2, undetvar.inst)) |
716 Type bound = upperBound(s); |
717 return false; |
717 // We should check the new upper bound against any of the |
|
718 // undetvar's lower bounds. |
|
719 for (Type t2 : undetvar.lobounds) { |
|
720 if (!isSubtype(t2, bound)) |
|
721 return false; |
|
722 } |
|
723 undetvar.hibounds = undetvar.hibounds.prepend(bound); |
|
724 break; |
|
725 } |
|
726 case SUPER: { |
|
727 Type bound = lowerBound(s); |
|
728 // We should check the new lower bound against any of the |
|
729 // undetvar's lower bounds. |
|
730 for (Type t2 : undetvar.hibounds) { |
|
731 if (!isSubtype(bound, t2)) |
|
732 return false; |
|
733 } |
|
734 undetvar.lobounds = undetvar.lobounds.prepend(bound); |
|
735 break; |
|
736 } |
718 } |
737 } |
719 return true; |
738 return true; |
720 } else { |
739 } else { |
721 return isSameType(t, s); |
740 return isSameType(t, s); |
722 } |
741 } |
2823 return arraySuperType; |
2842 return arraySuperType; |
2824 } |
2843 } |
2825 // </editor-fold> |
2844 // </editor-fold> |
2826 |
2845 |
2827 // <editor-fold defaultstate="collapsed" desc="Greatest lower bound"> |
2846 // <editor-fold defaultstate="collapsed" desc="Greatest lower bound"> |
|
2847 public Type glb(List<Type> ts) { |
|
2848 Type t1 = ts.head; |
|
2849 for (Type t2 : ts.tail) { |
|
2850 if (t1.isErroneous()) |
|
2851 return t1; |
|
2852 t1 = glb(t1, t2); |
|
2853 } |
|
2854 return t1; |
|
2855 } |
|
2856 //where |
2828 public Type glb(Type t, Type s) { |
2857 public Type glb(Type t, Type s) { |
2829 if (s == null) |
2858 if (s == null) |
2830 return t; |
2859 return t; |
2831 else if (isSubtypeNoCapture(t, s)) |
2860 else if (isSubtypeNoCapture(t, s)) |
2832 return t; |
2861 return t; |