Skip to content

Implicit conversions can add extension type members #19888

Closed
@lihaoyi

Description

@lihaoyi

Compiler version

3.4.0

Minimized code

object Main{
  object Foo
  object Bar{ type Qux = Unit }


  implicit def conv(f: Foo.type): Bar.type = Bar

  def B: Bar.type = Bar

  def main(args: Array[String]): Unit = {
    val x: Foo.Qux = null
    val y: B.Qux = null
    println(x)
    println(y)
  }  
}

Output

null
null

Expectation

I would expect A.Qux to be a compilation error, because A does not have a member type Qux, without the implicit conversion.

I would expect B.Qux to be a compilation error, because B is not a stable path prefix for the B.Qux path dependent type

The equivalent code is a compilation error in Scala 2.x. It definitely seems weird that implicit conversions and other non-stable methods can be used in the path dependent type's path prefix!

TBH not sure if this is bug or feature, but @odersky mentioned it might be a bug, so filing it here for posterity.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions