Skip to content

When a trait which extends a class with constructor is initialised directly, it may give confusing message #22061

Open
@tribbloid

Description

@tribbloid

Compiler version

3.5.2

Minimized code

object TraitExtendingClass {

  abstract class A()(
      implicit
      val x: Int = 3
  )

  trait B extends A

  @main def main(): Unit = {

    val b = new B {} //<-- error happens here
    val c = new B() {} //<-- error happens here

    println(b.x)
  }
}

Output

[Error] /xxx/TraitExtendingClass.scala:14:13: method $lessinit$greater$default$1 in object A must be called with () argument

No idea where $lessinit$greater$default$ came from

Expectation

the error message should be like "trait B has to be constructed with a constructor of class A"

In Scala 2.13 this actually succeeded (because of implicit eta-reduction of 0-arity constructor), which may explained the confusing error message

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions