How to ensure compilation failure using type parameters with subtyping

I want to ensure that a method call will fail at compilation time (using Dotty 3.0.0-RC1).
Code is provided at the end. More specifically I have a method:

    def do1[T <: IsA](t:T): Unit = () 

So this should work:


but this should not because IsA is not a subtype of IsB:

    UseBaseA.do1(IsB()) // Not failing

However it fails at run-time with a java.lang.AbstractMethodError.
If I use an abstract type member however, I can generate a compile error.
In the code below compilation will fail here:

    UseBaseA.do2(IsB()) // Ok, fails

The code below is found in scastie.


  class BaseToCompare
  class IsA extends BaseToCompare
  class IsB extends BaseToCompare
  class IsC extends IsA

  trait UseBase:
    type TT <: BaseToCompare

    def do1[T <: BaseToCompare](t:T): Unit 
    def do2(t:TT): Unit 
  object UseBaseA extends UseBase :
    type TT = IsA

    def do1[T <: IsA](t:T): Unit = () 
    def do2(t:TT): Unit = ()

  def run: Unit =

    UseBaseA.do1(IsB()) // Not failing
    //UseBaseA.do2(IsB()) // Ok, fails
    UseBaseA.do2(IsC()) // How to get this to fail, only

    // Nothing to do