Skip to content

Spurious type error with value of weird intersection #5699

Closed
@LPTK

Description

@LPTK

The following:

type M = { type T[+A] } & { type T[-A] }
val M: M = ().asInstanceOf[M]
M: M

raises:

-- [E007] Type Mismatch Error: /tmp/scastie3590197869340764976/src/main/scala/main.scala:10:2 
10 |  M: M
   |  ^
   |found:    Test.M(Test.M')
   |required: Test.M
   |
   |where:    M  is a type in object Test which is an alias of Object{T <: ([+A] => Any)} & Object{T <: ([-A] => Any)}
   |          M' is a value in object Test

It also happens in the REPL without even ascribing M:

scala> M
1 |M
  |^
  |Found:    M(M')
  |Required: M
  |
  |where:    M  is a type which is an alias of Object{T <: ([+A] => Any)} & Object{T <: ([-A] => Any)}
  |          M' is a value

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions