Skip to content

Implicitly-created companion object clashes when extending inner class with same name #7769

Open
@scabug

Description

@scabug

This code fails to compile

class Foo { class Inner(x: Int = 42) }
class Bar extends Foo { class Inner(y: Int = 0) extends super.Inner() }

with the error message

scalatest.scala:2: error: overriding object Inner in class Foo;
 object Inner cannot override final member
class Bar extends Foo { class Inner(y: Int = 0) extends super.Inner() }
                              ^
one error found

This is a bit misleading if you didn't expect the object Inner to be created, particularly as it only refuses to compile if the companion object needs to be created (e.g. when there are default parameters).

A more explanatory error message would probably suffice for now...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions