Skip to content

Subtyping info lost when pattern matching on type of expression #15735

Closed
@prolativ

Description

@prolativ

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions