Skip to content

Improve overriding error message for exports #8347

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 1 commit into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ object RefChecks {
s"$clazz inherits conflicting members:\n "
+ infoStringWithLocation(other) + " and\n " + infoStringWithLocation(member)
+ "\n(Note: this can be resolved by declaring an override in " + clazz + ".)")
else if member.is(Exported) then
overrideError("cannot override since it comes from an export")
else
overrideError("needs `override` modifier")
else if (other.is(AbsOverride) && other.isIncompleteIn(clazz) && !member.is(AbsOverride))
Expand Down
20 changes: 20 additions & 0 deletions tests/neg/exports1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
object A:
def f: String = ""

trait B:
def f: String = "abc"

trait B2 extends B:
override def f: String = "abc"

object D extends B:
object b extends B
export b._ // ok

object D1 extends B:
object b extends B
export b.f // error

object D2 extends B:
object b2 extends B2
export b2.f // error
5 changes: 5 additions & 0 deletions tests/neg/exports2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Error: tests/neg/exports2.scala:8:11 --------------------------------------------------------------------------------
8 | export A._ // error
| ^
| error overriding method f in trait B of type => String;
| method f of type => String cannot override since it comes from an export
9 changes: 9 additions & 0 deletions tests/neg/exports2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object A:
def f: String = ""

trait B:
def f: String = "abc"

object C extends B:
export A._ // error