"case Foo fooButNull" is equivalent to "case null" but with a binding typed as Foo that's why i ask if it should even compile,
the compiler should ask for an explicit "case null".

It may be "equivalent" in our eyes, but the language doesn't currently incorporate nullity into the type system.  So it is similar to other kinds of "equivalences", where the human knows more than the language, such as single-sealed classes:

    sealed interface I permits A { }
    final class A implements I { }

    I i = ...
    A a = i

As humans, we know that the I must be an A, but we'd have to change the set of assignment (and other) conversions to reflect that.  We could, but right now, the language doesn't know this.

I could construct other examples of things the programmer knows but the language doesn't, but I think you get my point -- if you want to raise this equivalence into the language, this is not merely about pattern dominance, this is an upgrade to the type system.


I'm not sure it should be include in the dominance, because Foo(int) is a subtype of Foo, so
  case Foo foo ->
  case Foo(int _) foo ->
should not compile.

Dominance already handles this case.  A type pattern `X x` dominates a record pattern `X(...)`.

Reply via email to