-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Disallow overriding val parameters #16096
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b5f307d
Disallow overriding val parameters
odersky 34d87db
Reject overrides only with -source future
odersky b1856e7
Drop checkInit tests that cause deprecation warnings
odersky d1862de
Fix specs2 code to be future proof
odersky dd85d57
Allow indirect inherited accessors
odersky a07d9e6
Fix remaining CB projects
odersky f43e98e
Emit errors again only under -source future
odersky fb75d96
Update compiler/src/dotty/tools/dotc/typer/RefChecks.scala
odersky 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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,6 @@ | ||
trait Pet(val name: String, rest: Int): | ||
def f(suffix: String) = s"$name$suffix$rest" | ||
|
||
class Birdie(override val name: String) extends Pet("huh", 1) // error | ||
|
||
|
This file contains 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,24 @@ | ||
trait X { | ||
type T | ||
def process(t: T): Unit | ||
} | ||
|
||
class Z(val x: X, val t: x.T) { | ||
def process(): Unit = x.process(t) | ||
} | ||
class Evil(x1: X, x2: X, t: x1.T) extends Z(x1, t) { | ||
override val x: X = x2 // error breaks connection between x and t | ||
} | ||
// alarm bells should be ringing by now | ||
|
||
// taking it to its conclusion... | ||
object x1 extends X { | ||
override type T = Int | ||
override def process(t: T): Unit = println("Int: " + t) | ||
} | ||
object x2 extends X { | ||
override type T = String | ||
override def process(t: T): Unit = println("String: " + t) | ||
} | ||
|
||
@main def Test = new Evil(x1, x2, 42).process() // BOOM: basically did x2.process(42) |
This file contains 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,31 @@ | ||
trait X: | ||
type T | ||
def process(t: T): Unit | ||
|
||
abstract class Z: | ||
def x1: X | ||
val x: X = x1 | ||
def t: x.T | ||
def process(): Unit = x.process(t) | ||
|
||
class Evil extends Z: | ||
def x2: X | ||
override val x: X = x2 | ||
|
||
// alarm bells should be ringing by now | ||
|
||
// taking it to its conclusion... | ||
object X1 extends X: | ||
override type T = Int | ||
override def process(t: T): Unit = println("Int: " + t) | ||
|
||
object X2 extends X: | ||
override type T = String | ||
override def process(t: T): Unit = println("String: " + t) | ||
|
||
@main def Test = | ||
new Evil{ | ||
val x1 = X1 | ||
val x2 = X2 | ||
val t = 42 // error | ||
}.process() // BOOM: basically did x2.process(42) |
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
trait A(val s: String) { println(s) } | ||
trait B extends A { override val s = "B" } // requires override val s | ||
trait A(s: String) { println(s) } | ||
trait B extends A { val s = "B" } | ||
class C extends B // error | ||
@main def Test = C() |
This file contains 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 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,5 @@ | ||
class A(val x: Int) | ||
class B(override val x: Int) extends A(x) | ||
|
||
class C(x: Int) extends A(x) | ||
case class D(override val x: Int) extends C(x) |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 @@ | ||
|
||
class A(a: Int) | ||
|
||
class B extends A(1): | ||
val a = 2 // ok | ||
|
||
@main def Test = | ||
assert(B().a == 2) |
This file contains 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
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.
Some word is missing after
its
.We may want to add a
final
flag in the desugaring ifsourceVersion.isAtLeast(future)
.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.
Or we add
ParamAccessor
to the set ofEffectivelyFinalFlags
. But for the moment we want to treat them separately.