Skip to content

Type inference infers Any in multiple pattern match instead of more specific type #8041

@scabug

Description

@scabug

The type inference engine is unable to infer, that the variable t bound inside of the multiple pattern match is of type T:

scala> trait T; class A extends T; class B extends T
defined trait T
defined class A
defined class B

scala> def f(t: T): T = t match { case t @ (_: A | _: B) => t }
f: (t: T)T

scala> def f(t: Any): T = t match { case t @ (_: A | _: B) => t }
<console>:10: error: type mismatch;
 found   : Any
 required: T
       def f(t: Any): T = t match { case t @ (_: A | _: B) => t }
                                                              ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)inferpatmat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions