Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tribbloid opened this issue Dec 1, 2024 · 0 comments · May be fixed by #22344
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug

Comments

@tribbloid
Copy link

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

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 1, 2024
@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 3, 2024
@hamzaremmal hamzaremmal self-assigned this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants