Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fast-track deprecating nullary/nilary method overriding
Aka "promote -Xlint:override-nullary". This means warn by default & error under -Xsource:3.
- Loading branch information
Showing
34 changed files
with
193 additions
and
62 deletions.
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
nullary-override-3a.scala:4: error: method with a single empty parameter list overrides method without any parameter list | ||
def x: Int (defined in class A) | ||
class B extends A { override def x(): Int = 4 } | ||
^ | ||
nullary-override-3a.scala:16: error: method with a single empty parameter list overrides method without any parameter list | ||
def x: String (defined in trait T1) | ||
class Mix12b extends T1 with T2 { override def x() = "12b" } | ||
^ | ||
nullary-override-3a.scala:19: error: method with a single empty parameter list overrides method without any parameter list | ||
def x: String (defined in trait T1) | ||
class Mix21b extends T2 with T1 { override def x() = "21b" } | ||
^ | ||
3 errors |
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,40 @@ | ||
// scalac: -Werror -Wunused:nowarn -Xsource:3 | ||
// | ||
class A { def x: Int = 3 } | ||
class B extends A { override def x(): Int = 4 } | ||
|
||
|
||
trait T1 { def x: String = "1" } | ||
trait T2 { def x(): String = "2" } | ||
|
||
// without overrides you just get: error: class X inherits conflicting members: | ||
// def x: String (defined in trait T1) and | ||
// def x(): String (defined in trait T2) | ||
// (note: this can be resolved by declaring an `override` in class X.) | ||
|
||
// Mix12a in nullary-override-3b | ||
class Mix12b extends T1 with T2 { override def x() = "12b" } | ||
|
||
class Mix21a extends T2 with T1 { override def x = "21a" } | ||
class Mix21b extends T2 with T1 { override def x() = "21b" } | ||
|
||
import java.util.concurrent.atomic.{ AtomicMarkableReference => AMR } | ||
trait Ref1 { def getReference: String = "1" } | ||
trait Ref2 { def getReference(): String = "2" } | ||
|
||
// without overrides you just get: error: class X inherits conflicting members: | ||
// def getReference(): String (defined in class AtomicMarkableReference) and | ||
// def getReference: String (defined in trait Ref1) | ||
// (note: this can be resolved by declaring an `override` in class X.) | ||
|
||
class Mark1a extends AMR[String]("", false) with Ref1 { override def getReference = "1a" } | ||
class Mark1b extends AMR[String]("", false) with Ref1 { override def getReference() = "1b" } | ||
|
||
class Mark2a extends AMR[String]("", false) with Ref2 { override def getReference = "2a" } | ||
class Mark2b extends AMR[String]("", false) with Ref2 { override def getReference() = "2b" } | ||
|
||
class Mark12a extends AMR[String]("", false) with Ref1 with Ref2 { override def getReference = "12a" } | ||
class Mark12b extends AMR[String]("", false) with Ref1 with Ref2 { override def getReference() = "12b" } | ||
|
||
class Mark21a extends AMR[String]("", false) with Ref2 with Ref1 { override def getReference = "21a" } | ||
class Mark21c extends AMR[String]("", false) with Ref2 with Ref1 { override def getReference() = "21b" } |
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,7 @@ | ||
nullary-override-3b.scala:6: error: method without a parameter list overrides a method with a single empty one | ||
class Q extends P { override def x: Int = 4 } | ||
^ | ||
nullary-override-3b.scala:11: error: method without a parameter list overrides a method with a single empty one | ||
class Mix12a extends T1 with T2 { override def x = "12a" } | ||
^ | ||
2 errors |
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,12 @@ | ||
// scalac: -Werror -Wunused:nowarn -Xsource:3 | ||
// | ||
// P has parens | ||
class P { def x(): Int = 3 } | ||
// Q is questionable | ||
class Q extends P { override def x: Int = 4 } | ||
|
||
trait T1 { def x: String = "1" } | ||
trait T2 { def x(): String = "2" } | ||
|
||
class Mix12a extends T1 with T2 { override def x = "12a" } | ||
// the rest in nullary-override-3a |
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,9 +1,18 @@ | ||
nullary-override.scala:15: warning: nullary method assumes an empty parameter list from the overridden definition | ||
nullary-override.scala:15: warning: method without a parameter list overrides a method with a single empty one | ||
class Q extends P { override def x: Int = 4 } | ||
^ | ||
nullary-override.scala:4: warning: non-nullary method overrides nullary method | ||
nullary-override.scala:36: warning: method without a parameter list overrides a method with a single empty one | ||
class Mix12a extends T1 with T2 { override def x = "12a" } | ||
^ | ||
nullary-override.scala:4: warning: method with a single empty parameter list overrides method without any parameter list | ||
class B extends A { override def x(): Int = 4 } | ||
^ | ||
nullary-override.scala:37: warning: method with a single empty parameter list overrides method without any parameter list | ||
class Mix12b extends T1 with T2 { override def x() = "12b" } | ||
^ | ||
nullary-override.scala:40: warning: method with a single empty parameter list overrides method without any parameter list | ||
class Mix21b extends T2 with T1 { override def x() = "21b" } | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
5 warnings | ||
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
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 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,10 @@ | ||
// scalac: -Werror -Wunused:nowarn -Xsource:3 | ||
// | ||
class C extends java.lang.CharSequence { | ||
def charAt(x$1: Int): Char = ??? | ||
def length: Int = ??? | ||
def subSequence(x$1: Int, x$2: Int): CharSequence = ??? | ||
} | ||
|
||
// Welcome to the Happy J | ||
class J { override def toString = "Happy J" } |
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 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 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
Oops, something went wrong.