Skip to content

Commit bf264df

Browse files
committed
Streamline approximateWildcards logic
1 parent f4f03bb commit bf264df

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ trait ConstraintHandling {
7979
def fullBounds(param: TypeParamRef)(using Context): TypeBounds =
8080
nonParamBounds(param).derivedTypeBounds(fullLowerBound(param), fullUpperBound(param))
8181

82-
/** If true: eliminate wildcards in bounds by avoidance.
83-
* Otherwise replace them by fresh variables, except that
84-
* in mode TypeVarsMissContext, wildcards are always eliminated by approximation.
82+
/** If true, eliminate wildcards in bounds by avoidance, otherwise replace
83+
* them by fresh variables.
8584
*/
8685
protected def approximateWildcards: Boolean = true
8786

@@ -96,7 +95,7 @@ trait ConstraintHandling {
9695
if !isUpper then variance = -1
9796
def apply(t: Type): Type = t match
9897
case t: WildcardType =>
99-
if approximateWildcards || ctx.mode.is(Mode.TypevarsMissContext) then
98+
if approximateWildcards then
10099
val bounds = t.effectiveBounds
101100
range(bounds.lo, bounds.hi)
102101
else

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,14 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
139139
try topLevelSubType(tp1, tp2)
140140
finally useNecessaryEither = saved
141141

142-
override protected def approximateWildcards: Boolean = useNecessaryEither
142+
/** Use avoidance to get rid of wildcards in constraint bounds if
143+
* we are doing a neccessary comparison, or the mode is TypeVarsMissContext.
144+
* The idea is that under either of these conditions we are not interested
145+
* in creating a fresh type variable to replace the wildcard. I verified
146+
* that several tests break if one or the other part of the disjunction is dropped.
147+
*/
148+
override protected def approximateWildcards: Boolean =
149+
useNecessaryEither || ctx.mode.is(Mode.TypevarsMissContext)
143150

144151
def testSubType(tp1: Type, tp2: Type): CompareResult =
145152
GADTused = false

0 commit comments

Comments
 (0)