scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

A (non implicit) value class definition in an object clashes with an inherited nullary method #12857

Closed noresttherein closed 10 months ago

noresttherein commented 10 months ago

Reproduction steps

Scala version: (2.13.11

trait A {
    def Damn :String = ""
}

object B extends A {
    class Damn(val self :String) extends AnyVal
}

Problem

incompatible type in overriding
def Damn: String (defined in trait A);
 found   : B.Damn.type
 required: String
    class Damn(val self :String) extends AnyVal

Omitting extends AnyVal, or, interestingly enough, adding a type parameter to method def Damn[X] :String fixes the issue.

som-snytt commented 10 months ago

The spec mandates that the value class have a companion.

You always minimally get extensions for hashCode and equals.

The terms can be disambiguated using old-timey techniques.

It's a bug that dotty doesn't notice the error, or perhaps it's fooled by its encoding of object as lazy.

trait A {
  def Damn: String = "flames"
  //def Damn(implicit i: DummyImplicit): String = "flames"
}

object B extends A {
  class Damn(val self: String) extends AnyVal
}

object Test {
  def main(args: Array[String]): Unit = println {
    //new B.Damn("perdition").hashCode
    B.Damn
  }
}