Skip to content

Commit 7f3ddd0

Browse files
committed
Verify that constraints do not contain wildcard types
1 parent 36d9c26 commit 7f3ddd0

File tree

5 files changed

+8
-2
lines changed

5 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ object Config {
3434
*/
3535
inline val checkConstraintsPropagated = false
3636

37+
/** Check that constraint bounds do not contain wildcard types */
38+
inline val checkNoWildcardsInConstraint = true
39+
3740
/** If a constraint is over a type lambda `tl` and `tvar` is one of
3841
* the type variables associated with `tl` in the constraint, check
3942
* that the origin of `tvar` is a parameter of `tl`.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ trait ConstraintHandling {
270270
var trackedPolis: List[PolyType] = Nil
271271
def apply(tp: Type) = tp match
272272
case tp: WildcardType =>
273+
assert(false)
273274
val poly = PolyType(tpnme.EMPTY :: Nil)(pt => tp.bounds :: Nil, pt => defn.AnyType)
274275
trackedPolis = poly :: trackedPolis
275276
poly.paramRefs.head
@@ -309,6 +310,7 @@ trait ConstraintHandling {
309310
def apply(tp: Type) = mapOver {
310311
tp match
311312
case tp: WildcardType =>
313+
assert(false)
312314
pickOneBound(tp.bounds)
313315
case tp: TypeParamRef if substWildcards.trackedPolis.contains(tp.binder) =>
314316
pickOneBound(fullBounds(tp))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
376376
Nil
377377

378378
private def updateEntry(current: This, param: TypeParamRef, tp: Type)(using Context): This = {
379+
if Config.checkNoWildcardsInConstraint then assert(!tp.containsWildcardTypes)
379380
var current1 = boundsLens.update(this, current, param, tp)
380381
tp match {
381382
case TypeBounds(lo, hi) =>

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

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

142-
override protected def allowWildcards: Boolean = !useNecessaryEither
142+
override protected def approximateWildcards: Boolean = useNecessaryEither
143143

144144
def testSubType(tp1: Type, tp2: Type): CompareResult =
145145
GADTused = false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ object Types {
439439

440440
/** Does this type contain wildcard types? */
441441
final def containsWildcardTypes(using Context) =
442-
existsPart(_.isInstanceOf[WildcardType], stopAtStatic = true)
442+
existsPart(_.isInstanceOf[WildcardType], stopAtStatic = true, forceLazy = false)
443443

444444
// ----- Higher-order combinators -----------------------------------
445445

0 commit comments

Comments
 (0)