scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Subtyping info lost when pattern matching on type of expression

Open prolativ opened this issue 3 years ago • 0 comments

Compiler version

3.2.1-RC1-bin-20220721-634c580-NIGHTLY and earlier

Minimized code

//> using scala "3.2.1-RC1-bin-20220721-634c580-NIGHTLY"

import scala.quoted.*

trait Foo:
  type Number <: Int

trait Bar[T <: Int]

private def collectImpl[T : Type](using Quotes) =
  val expr: Expr[Foo] = ???
  expr match
    case '{ $enc: Foo { type Number = num } } =>
      Type.of[T] match
        case '[Bar[`num`]] => '{}

Output

[error] Macro.scala:15:20: Type argument num does not conform to upper bound Int
[error]         case '[Bar[`num`]] => '{}
[error]                    ^

Expectation

The compiler should be aware that num has to be a subtype of Int and the compilation should succeed

prolativ avatar Jul 22 '22 14:07 prolativ