Closed Linyxus closed 3 years ago
We shouldn't even attempt to record any constraint here, there's no useful information ATM to extract. This is yet another problem that would be best fixed by avoiding the Skolem hack in PatternTypeConstrainer.
If it is not clear how to get rid of the Skolem hack at this point, would it be okay to workaround this issue by checking whether the bound is a Skolem with its underlying type same as the narrowed type parameter?
def isAliasSkolem: Boolean = bound match {
case SkolemType(tp) if tp == tr => true
case _ => false
}
if isAliasSkolem then false
else ...
The Skolem hack is that in PatternTypeConstrainer, we wrap one of the types into a Skolem and substitute type arguments in the other type to trigger a specific codepath in TypeComparer. This is sort-of morally justified by what a Skolem type is, but it has led to a bunch of subtle issues and at this point we really should just inline the codepath instead.
Compiler version
3.0.0
Minimized code
Output
Expectation
Should compile without crashing.
Cause
After the first pattern matching, the GADT bounds will become
The
(?1 : A)
here is theSkolemType
we created for pattern type inconstrainSimplePatternType
.When typing the second pattern matching, the GADT bounds will become
and in
ConstraintHandling#addOneBound
we will askisSubType (?1 : A) | (?2 : B) <:< Any?
to check the narrowed bounds. Note that when we are running the subtyping check, the GADT bounds ofB
have already been been updated to(?1 : A) | (?2 : B)
. Related trace on the infinite loop:@abgruszecki