-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2473: Check self for inner class redefinitions #2553
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
Conversation
tests/neg/i2473.scala
Outdated
@@ -0,0 +1,7 @@ | |||
trait Foo { trait Inner } | |||
trait Bar { foo: Foo => | |||
type Inner <: foo.Inner // error: type Inner cannot have the same name as trait Inner in trait Foo -- class definitions cannot be overridden |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's not an override, it's a shadowing, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes. I reused the old error message. I will improve it to make the distinction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I don't think that shadowing is the right term either, consider:
trait Foo {
val x: Int = 1
}
trait Bar { foo: Foo =>
val x: String = ""
}
In both scalac and dotty, this code compiles, but if you try to make an instance of Bar
, it fails:
object Test {
def main(args: Array[String]): Unit = {
new Foo with Bar {}
}
}
-- Error: try/i2473.scala:14:4 -------------------------------------------------
14 | new Foo with Bar {}
| ^
| class $anon inherits conflicting members:
| value x in trait Foo of type Int and
| value x in trait Bar of type String
| (Note: this can be resolved by declaring an override in class $anon.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the message to print
-- [E068] Syntax Error: tests/neg/i2473.scala:3:7 ------------------------------
3 | type Inner <: foo.Inner // error
| ^
|type Inner cannot have the same name as trait Inner in trait Foo -- cannot define type member with the same name as a trait member in self reference foo.
|(Note: this can be resolved by using another name)
-- [E068] Syntax Error: tests/neg/i2473.scala:6:8 ------------------------------
6 | class Inner // error
| ^
|class Inner cannot have the same name as trait Inner in trait Foo -- cannot define class member with the same name as a trait member in self reference baz.
|(Note: this can be resolved by using another name)
extends Message(CannotHaveSameNameAsID) { | ||
val msg = hl"""$sym cannot have the same name as ${cls.showLocated} -- class definitions cannot be overridden""" | ||
import CannotHaveSameNameAs._ | ||
def resonMessage: String = reason match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: reson -> reason
No description provided.