Skip to content

asInstanceOf causes type mismatch error when used in method argument position #12739

Closed
@japgolly

Description

@japgolly

Compiler version

3.0.0

Minimized code

object X {

  class CA[A]
  type C = CA[_]
  val c: C = ???
  def f[A](r: CA[A]) = ()

  // works
  f(c)

  // works
  val x = c.asInstanceOf[C]
  f(x)

  // error
  f(c.asInstanceOf[C])

  // works
  f(c.asInstanceOf[c.type])
}

Output

[error] -- [E007] Type Mismatch Error: a.scala:16:18 
[error] 16 |  f(c.asInstanceOf[C])
[error]    |    ^^^^^^^^^^^^^^^^^
[error]    |    Found:    X.C
[error]    |    Required: X.CA[A]
[error]    |
[error]    |    where:    A is a type variable
[error] one error found

Expectation

No error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions