Skip to content
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

Confusing first error message that overriding type members is possible #6001

Closed
scabug opened this issue Jun 28, 2012 · 7 comments · Fixed by scala/scala#6350
Closed

Confusing first error message that overriding type members is possible #6001

scabug opened this issue Jun 28, 2012 · 7 comments · Fixed by scala/scala#6350
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 28, 2012

When trying to override a concrete type member without a override keyword the compiler returns an error saying that the override keyword must be used.

scala> :paste
// Entering paste mode (ctrl-D to finish)

class MyString
trait A { type Hello}
class AClass extends A{ type Hello = MyString}

// Exiting paste mode, now interpreting.

defined class MyString
defined trait A
defined class AClass


scala> class B extends AClass{ type Hello = MyString with Serializable}
<console>:13: error: overriding type Hello in class AClass, which equals MyStrin
g;
 type Hello needs `override' modifier
       class B extends AClass{ type Hello = MyString with Serializable}
                                    ^

But after applying the overriding keyword the compiler says that the type member is incompatible. It could already be said before.
Maybe also a more unambiguous message like "Overriding concrete type members is not allowed".
"type Hello has incompatible type" suggests too much that the error is in this case the relation between MyClass and MyClass with Serializable.

scala> class B extends AClass{ override type Hello =MyString with Serializable}
<console>:13: error: overriding type Hello in class AClass, which equals MyStrin
g;
 type Hello has incompatible type
       class B extends AClass{ override type Hello =MyString with Serializable}
                                           ^
@scabug
Copy link
Author

scabug commented Jun 28, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6001?orig=1
Reporter: DaveScala (davescala)
Affected Versions: 2.10.0-M4

@scabug
Copy link
Author

scabug commented Jun 28, 2012

DaveScala (davescala) said:
This is the thread
http://groups.google.com/group/scala-user/browse_thread/thread/b22e758dbf514baf

There seems to be one possibility when overriding concrete type members is allowed by the compiler and that is when the definition is exactly the same.

@scabug
Copy link
Author

scabug commented Jun 28, 2012

DaveScala (davescala) said:
Suggestion:
"Overriding concrete type aliases is not allowed except when equivalent.".

@scabug
Copy link
Author

scabug commented Mar 15, 2013

@adriaanm said:
Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Aug 5, 2014

@gkossakowski said:
The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@retronym said:
Updating fix-by version to 2.11.5.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
eed3si9n added a commit to eed3si9n/scala that referenced this issue Feb 26, 2018
Fixes scala/bug#6001

This fixes the error message for overriding a concrete type alias.

### before

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 type A1 has incompatible type
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

### after

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 overriding concrete type alias type A1 is not allowed except when equivalent
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

This error message was suggested in scala/bug#6001 (comment).
eed3si9n added a commit to eed3si9n/scala that referenced this issue Mar 3, 2018
Fixes scala/bug#6001

This fixes the error message for overriding a concrete type alias.

### before

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 type A1 has incompatible type
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

### after

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 overriding concrete type alias type A1 is not allowed except when equivalent
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

This error message was suggested in scala/bug#6001 (comment).
eed3si9n added a commit to eed3si9n/scala that referenced this issue Mar 4, 2018
Fixes scala/bug#6001

This fixes the error message for overriding a concrete type alias.

before

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 type A1 has incompatible type
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

after

```scala
override-concrete-type.scala:7: error: overriding type A1 in class Foo, which equals Something;
 overriding concrete type alias type A1 is not allowed except when equivalent
class Bar extends Foo { override type A1 = Something with Serializable }
                                      ^
one error found
```

This error message was suggested in scala/bug#6001 (comment).

Additionally, this improves "this can be resolved" note.

```scala
t5358.scala:3: error: class C inherits conflicting members:
  method hi in trait A of type => String and
  method hi in trait B of type => String
  (note: this can be resolved by declaring an `override' in class C.)
class C extends A with B
      ^
```
SethTisue added a commit to scala/scala that referenced this issue Apr 25, 2018
scala/bug#6001. Fix error message for overriding type alias
@SethTisue SethTisue modified the milestones: Backlog, 2.13.0-M4 Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants