Skip to content

Intersection types are not always commutative #19376

Open
@rskfocus

Description

@rskfocus

Compiler version

3.4.0-RC1

Minimized code

sealed trait Tagged[T]
sealed trait Row[A]

def run[R, A](tagged: Tagged[R & Row[A]], a: A): Tagged[R] = new Tagged[R] {}

/*
order of rows in type annotation affect either y or z compilation;
if changed to Tagged[Row[String] & Row[Int]] y fails to compile while z is not
*/
val x: Tagged[Row[Int] & Row[String]] = new Tagged[Row[Int] & Row[String]] {}

val y = run(x, 1) // compiles OK
val z = run(x, "s") // error

Output

Found:    ("s" : String)
Required: Int

Expectation

I expect that order of types in an intersection type doesn't affect type inference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions