Skip to content

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

Merged
merged 3 commits into from
May 29, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.)

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: reson -> reason

@felixmulder felixmulder merged commit e4bcbda into scala:master May 29, 2017
@allanrenucci allanrenucci deleted the fix-#2473 branch December 14, 2017 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants