Skip to content

Return type of method not checked when overriding methods from self type in trait #9736

@scabug

Description

@scabug

When overriding a method from the self type of a trait the return type is not checked so this compiles:

trait A {
    def a: Int
}
trait B { self: A =>
    override def a: String = "Well this should not compile"
} 

The compile error happens when B is used:

scala> class C extends A with B
<console>:9: error: overriding method a in trait A of type => Int;
 method a in trait B of type => String has incompatible type
       class C extends A with B
             ^

The compile error should already happen when defining B as the method overrides nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions