type MatchType[T] = T match
case Bar[?] => Nothing
case _ => T
I get the following error when using it somewhere else (unfortunately, the full code is hard to minimize):
trying to reduce MatchType[Bar[? <: Foo]] failed since selector Bar[? <: Foo] does not match case Bar[_] => Nothing and cannot be shown to be disjoint from it either.
How come Bar[? <: Foo] doesn’t match Bar[?]? And how can I write a type pattern that ensures a match against Bar[? <: Foo]?
I don’t fully understand (hopefully the compiler people can explain better) but it seems that the type parameter of Bar[_] is not known to comply with the type bound >: Foo.
So I was able to fix it by providing a type parameter that is known to comply with the type bound:
def bar[T >: Foo](b: Bar[T]): Nothing = foo(b)
Not sure why it complies with the bound written this way, but not the way you wrote (I’ve never seen the ? syntax before). I’m sure someone knows.
Here is the part of the code where I originally encountered the issue. It can be reproduced by uncommenting loopExample2 and building the project. But investigating it is probably not worth your effort. The code might be hard to follow, and is very much a work in progress.
? represents an unspecified type (formerly _). See the documentation here and here.