@@ -778,7 +778,15 @@ object Contexts {
778778 sealed abstract class GADTMap {
779779 def addEmptyBounds (sym : Symbol )(implicit ctx : Context ): Unit
780780 def addBound (sym : Symbol , bound : Type , isUpper : Boolean )(implicit ctx : Context ): Boolean
781+ def isLess (sym1 : Symbol , sym2 : Symbol )(implicit ctx : Context ): Boolean
781782 def bounds (sym : Symbol )(implicit ctx : Context ): TypeBounds
783+
784+ /** Full bounds of `sym`, including TypeRefs to other lower/upper symbols.
785+ *
786+ * Note that underlying operations perform subtype checks - for this reason, recursing on `fullBounds`
787+ * of some symbol when comparing types might lead to infinite recursion. Consider `bounds` instead.
788+ */
789+ def fullBounds (sym : Symbol )(implicit ctx : Context ): TypeBounds
782790 def contains (sym : Symbol )(implicit ctx : Context ): Boolean
783791 def approximation (sym : Symbol , fromBelow : Boolean )(implicit ctx : Context ): Type
784792 def debugBoundsDescription (implicit ctx : Context ): String
@@ -807,6 +815,12 @@ object Contexts {
807815 override protected def constraint = myConstraint
808816 override protected def constraint_= (c : Constraint ) = myConstraint = c
809817
818+ override protected def externalize (param : TypeParamRef )(implicit ctx : Context ): Type =
819+ reverseMapping(param) match {
820+ case sym : Symbol => sym.typeRef
821+ case null => param
822+ }
823+
810824 override def isSubType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Boolean = ctx.typeComparer.isSubType(tp1, tp2)
811825 override def isSameType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Boolean = ctx.typeComparer.isSameType(tp1, tp2)
812826
@@ -866,12 +880,21 @@ object Contexts {
866880 }, gadts)
867881 } finally boundAdditionInProgress = false
868882
883+ override def isLess (sym1 : Symbol , sym2 : Symbol )(implicit ctx : Context ): Boolean =
884+ constraint.isLess(tvar(sym1).origin, tvar(sym2).origin)
885+
886+ override def fullBounds (sym : Symbol )(implicit ctx : Context ): TypeBounds =
887+ mapping(sym) match {
888+ case null => null
889+ case tv => removeTypeVars(fullBounds(tv.origin)).asInstanceOf [TypeBounds ]
890+ }
891+
869892 override def bounds (sym : Symbol )(implicit ctx : Context ): TypeBounds = {
870893 mapping(sym) match {
871894 case null => null
872895 case tv =>
873896 def retrieveBounds : TypeBounds = {
874- val tb = constraint.fullBounds (tv.origin)
897+ val tb = bounds (tv.origin)
875898 removeTypeVars(tb).asInstanceOf [TypeBounds ]
876899 }
877900 (
@@ -883,10 +906,7 @@ object Contexts {
883906 boundCache = boundCache.updated(sym, bounds)
884907 bounds
885908 }
886- ).reporting({ res =>
887- // i"gadt bounds $sym: $res"
888- " "
889- }, gadts)
909+ )// .reporting({ res => i"gadt bounds $sym: $res" }, gadts)
890910 }
891911 }
892912
@@ -984,7 +1004,7 @@ object Contexts {
9841004 sb ++= constraint.show
9851005 sb += '\n '
9861006 mapping.foreachBinding { case (sym, _) =>
987- sb ++= i " $sym: ${bounds (sym)}\n "
1007+ sb ++= i " $sym: ${fullBounds (sym)}\n "
9881008 }
9891009 sb.result
9901010 }
@@ -993,7 +1013,9 @@ object Contexts {
9931013 @ sharable object EmptyGADTMap extends GADTMap {
9941014 override def addEmptyBounds (sym : Symbol )(implicit ctx : Context ): Unit = unsupported(" EmptyGADTMap.addEmptyBounds" )
9951015 override def addBound (sym : Symbol , bound : Type , isUpper : Boolean )(implicit ctx : Context ): Boolean = unsupported(" EmptyGADTMap.addBound" )
1016+ override def isLess (sym1 : Symbol , sym2 : Symbol )(implicit ctx : Context ): Boolean = unsupported(" EmptyGADTMap.isLess" )
9961017 override def bounds (sym : Symbol )(implicit ctx : Context ): TypeBounds = null
1018+ override def fullBounds (sym : Symbol )(implicit ctx : Context ): TypeBounds = null
9971019 override def contains (sym : Symbol )(implicit ctx : Context ) = false
9981020 override def approximation (sym : Symbol , fromBelow : Boolean )(implicit ctx : Context ): Type = unsupported(" EmptyGADTMap.approximation" )
9991021 override def debugBoundsDescription (implicit ctx : Context ): String = " EmptyGADTMap"
0 commit comments