-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handle case where abstract overrides miss an implementation #14893
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Error: tests/neg/i11170.scala:7:15 ---------------------------------------------------------------------------------- | ||
7 |abstract class A extends U[String] // error | ||
| ^ | ||
| Member method foo of mixin trait U is missing a concrete super implementation in class A. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
trait T[X] { | ||
def foo(x: X): X | ||
} | ||
trait U[X] extends T[X] { | ||
abstract override def foo(x: X): X = super.foo(x) | ||
} | ||
abstract class A extends U[String] // error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package apackage { | ||
|
||
abstract class A { | ||
protected val x: Int | ||
} | ||
abstract class A2 { | ||
val x: Int | ||
} | ||
} | ||
|
||
package bpackage { | ||
import apackage._ | ||
|
||
trait B extends A { | ||
println(x) | ||
} | ||
trait B2 extends A2 { | ||
println(x) | ||
} | ||
} | ||
|
||
package cpackage { | ||
import apackage._ | ||
import bpackage._ | ||
|
||
case class C(override protected val x: Int) extends A with B // error | ||
case class C2(override val x: Int) extends A2 with B2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
trait MathSig { | ||
def sqrt(x: Double): Double | ||
} | ||
|
||
trait MathSpec extends MathSig { | ||
val epsilon = 0.00001 | ||
abstract override def sqrt(x: Double) = { | ||
require(x >= 0) | ||
super.sqrt(x) | ||
} ensuring { result => | ||
(x * x - result).abs < epsilon | ||
} | ||
} | ||
|
||
trait MathImpl extends MathSig { | ||
def sqrt(x: Double): Double = | ||
??? | ||
} | ||
|
||
object Math extends MathImpl | ||
with MathSpec |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this should compile. "It's just a protected member." The ticket says it compiles if everything is in a single package.
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 Scala 2.13 also refuses this one. Is that a known bug?
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 see Scala 3 has a different definition of protected. It disalllows access to protected Java members from traits
at scala/bug#3564
Maybe Scala just makes everything public if it wants to do something like that.
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.
The Scala 3 ticket was noticed at scala/bug#12249 which is just Scala classes. The other link is a Java base class with protected member. I haven't reflected deeply yet.
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 am not sure about it either. But at least we don't crash anymore, and do the same thing as Scala 2.13 does.