-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tests from neg-custom-args/fatal-warnings to neg
- Loading branch information
1 parent
46f2db6
commit fb8426a
Showing
10 changed files
with
311 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:18:15 ----------------------------------------------------- | ||
18 | class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
| ^ | ||
| value x in class Derived shadows field x inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:18:24 ----------------------------------------------------- | ||
18 | class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
| ^ | ||
| value y in class Derived shadows field y inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:20:2 ------------------------------------------------------ | ||
20 | private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) | ||
| ^ | ||
| value shadowed2 in class Derived shadows field shadowed2 inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:21:2 ------------------------------------------------------ | ||
21 | private[this] val shadowed3 = 3 + 3 // error | ||
| ^ | ||
| value shadowed3 in class Derived shadows field shadowed3 inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:23:2 ------------------------------------------------------ | ||
23 | private val shadowed5 = 5 + 5 // error | ||
| ^ | ||
| value shadowed5 in class Derived shadows field shadowed5 inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:34:20 ----------------------------------------------------- | ||
34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error | ||
| ^ | ||
| value x in class UnderDerived shadows field x inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:34:28 ----------------------------------------------------- | ||
34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error | ||
| ^ | ||
| value y in class UnderDerived shadows field y inherited from class Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612a.scala:34:36 ----------------------------------------------------- | ||
34 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error | ||
| ^ | ||
| value z in class UnderDerived shadows field z inherited from class Base |
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,42 @@ | ||
// scalac: -Xlint:private-shadow | ||
|
||
object i17612a: | ||
class Base(var x: Int, val y: Int, var z: Int): | ||
var shadowed2 = 2 | ||
val shadowed3 = 3 | ||
val shadowed4 = 4 | ||
protected var shadowed5 = 5 | ||
//var shadowed6 = 6 | ||
|
||
val notShadowed = -1 | ||
private val notShadowed2 = -2 | ||
//val fatalOverride = 0 | ||
|
||
def increment(): Unit = | ||
x = x + 1 | ||
|
||
class Derived(x : Int, y: Int, z2: Int) extends Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
private def hello() = 4 | ||
private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) | ||
private[this] val shadowed3 = 3 + 3 // error | ||
//private[Derived] val fatalOverride = 0 // value fatalOverride of type Int has weaker access privileges; it should be public | ||
private val shadowed5 = 5 + 5 // error | ||
private val notShadowed2 = -4 | ||
//protected var shadowed6 = 6 + 6 // variable shadowed6 of type Int has weaker access privileges; it should be public | ||
|
||
def inFunctionScope() = | ||
val notShadowed = -2 // OK | ||
-2 | ||
|
||
override def toString = | ||
s"x : ${x.toString}, y : ${y.toString}" | ||
|
||
class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, y, z) // error // error // error | ||
|
||
def main(args: Array[String]) = | ||
val derived = new Derived(1, 1, 1) | ||
println(derived.toString) // yields x: '1', as expected | ||
derived.increment() | ||
println(derived.toString) // still x: '1', probably unexpected, for y it never prints the super value, less surprising | ||
println(derived.shadowed2) | ||
println(derived.shadowed3) |
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,32 @@ | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:21:15 --------------------------------------------- | ||
21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
| ^ | ||
| value x in class Derived shadows field x inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:21:33 --------------------------------------------- | ||
21 | class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
| ^ | ||
| value y in class Derived shadows field y inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:23:2 ---------------------------------------------- | ||
23 | private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) | ||
| ^ | ||
| value shadowed2 in class Derived shadows field shadowed2 inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:24:2 ---------------------------------------------- | ||
24 | private[this] val shadowed3 = 3 + 3 // error | ||
| ^ | ||
| value shadowed3 in class Derived shadows field shadowed3 inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:26:2 ---------------------------------------------- | ||
26 | private val shadowed5 = 5 + 5 // error | ||
| ^ | ||
| value shadowed5 in class Derived shadows field shadowed5 inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:41:20 --------------------------------------------- | ||
41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error | ||
| ^ | ||
| value x in class UnderDerived shadows field x inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:41:28 --------------------------------------------- | ||
41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error | ||
| ^ | ||
| value y in class UnderDerived shadows field y inherited from trait Base | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17612b/i17612b.scala:41:36 --------------------------------------------- | ||
41 | class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error | ||
| ^ | ||
| value z in class UnderDerived shadows field z inherited from trait Base |
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,44 @@ | ||
// scalac: -Xlint:private-shadow | ||
|
||
object i17612b: | ||
|
||
trait Base(var x: Int, val y: Int, var z: Int): | ||
var shadowed2 = 2 | ||
val shadowed3 = 3 | ||
val shadowed4 = 4 | ||
protected var shadowed5 = 5 | ||
|
||
val notShadowed = -1 | ||
private val notShadowed2 = -2 | ||
val notShadowedbyLambda = -2 | ||
|
||
def increment(): Unit = | ||
x = x + 1 | ||
|
||
trait BaseB | ||
trait BaseC(var x2: Int) | ||
|
||
class Derived(x : Int, x3: Int, y: Int, z2: Int) extends BaseB, BaseC(x3), Base(x, y + 1, z2): // error // error / for x, y translated to private[this] x field & shadowing var Base.x, Base.y | ||
private def hello() = 4 | ||
private val shadowed2 = 2 + 2 // error (In Scala 2 we cannot do that got the warning) | ||
private[this] val shadowed3 = 3 + 3 // error | ||
|
||
private val shadowed5 = 5 + 5 // error | ||
private val notShadowed2 = -4 | ||
|
||
val lambda: Int => Int => Int = | ||
notShadowedbyLambda => | ||
notShadowedbyLambda => | ||
notShadowedbyLambda * 2 | ||
|
||
def inFunctionScope() = | ||
val notShadowed = -2 // OK | ||
-2 | ||
|
||
override def toString = | ||
s"x : ${x.toString}, y : ${y.toString}" | ||
|
||
class UnderDerived(x: Int, y: Int, z: Int) extends Derived(x, 1, y, z) // error // error // error | ||
|
||
def main(args: Array[String]) = | ||
val derived = new Derived(1, 1, 1, 1) |
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 @@ | ||
object importTry: | ||
|
||
trait ImTrait | ||
|
||
class ImClass |
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,28 @@ | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:8:13 ------------------------------------------------------ | ||
8 | def foobar[D](in: D) = in.toString // error method parameter shadows some other type | ||
| ^ | ||
| Type parameter D for method foobar shadows the type defined by trait D in class B | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:9:13 ------------------------------------------------------ | ||
9 | type MySeq[D] = Seq[D] // error type member's parameter shadows some other type | ||
| ^ | ||
| Type parameter D for type MySeq shadows the type defined by trait D in class B | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:11:12 ----------------------------------------------------- | ||
11 | class Foo[T](t: T): // error class parameter shadows some other type | ||
| ^ | ||
| Type parameter T for class Foo shadows the type defined by type T in class B | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:12:11 ----------------------------------------------------- | ||
12 | def bar[T](w: T) = w.toString // error a type parameter shadows another type parameter | ||
| ^ | ||
| Type parameter T for method bar shadows the type defined by type T in class Foo | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:15:12 ----------------------------------------------------- | ||
15 | class C[M[List[_]]] // error | ||
| ^^^^^^^ | ||
| Type parameter List for class C shadows the type defined by type List in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:16:11 ----------------------------------------------------- | ||
16 | type E[M[List[_]]] = Int // error | ||
| ^^^^^^^ | ||
| Type parameter List for type E shadows the type defined by type List in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613a.scala:17:14 ----------------------------------------------------- | ||
17 | def foo[N[M[List[_]]]] = ??? // error | ||
| ^^^^^^^ | ||
| Type parameter List for method foo shadows the type defined by type List in package scala |
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,23 @@ | ||
// scalac: -Xlint:type-parameter-shadow | ||
|
||
object i17613a: | ||
class B: | ||
type T = Int | ||
trait D | ||
|
||
def foobar[D](in: D) = in.toString // error method parameter shadows some other type | ||
type MySeq[D] = Seq[D] // error type member's parameter shadows some other type | ||
|
||
class Foo[T](t: T): // error class parameter shadows some other type | ||
def bar[T](w: T) = w.toString // error a type parameter shadows another type parameter | ||
|
||
// even deeply nested... | ||
class C[M[List[_]]] // error | ||
type E[M[List[_]]] = Int // error | ||
def foo[N[M[List[_]]]] = ??? // error | ||
|
||
// ...but not between type parameters in the same list | ||
class F[A, M[N[A]]] | ||
type G[A, M[L[A]]] = Int | ||
def bar[A, N[M[L[A]]]] = ??? | ||
def main(args: Array[String]) = println("Test for type parameter shadow") |
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,56 @@ | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:9:13 ---------------------------------------------- | ||
9 | def foobar[ImTrait](in: D) = in.toString // error | ||
| ^^^^^^^ | ||
| Type parameter ImTrait for method foobar shadows the type defined by trait ImTrait in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:10:13 --------------------------------------------- | ||
10 | type MySeq[ImTrait] = Seq[D] // error | ||
| ^^^^^^^ | ||
| Type parameter ImTrait for type MySeq shadows the type defined by trait ImTrait in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:12:14 --------------------------------------------- | ||
12 | def foobar2[ImClass](in: D) = in.toString // error | ||
| ^^^^^^^ | ||
| Type parameter ImClass for method foobar2 shadows the type defined by class ImClass in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:13:14 --------------------------------------------- | ||
13 | type MySeq2[ImClass] = Seq[D] // error | ||
| ^^^^^^^ | ||
| Type parameter ImClass for type MySeq2 shadows the type defined by class ImClass in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:16:24 --------------------------------------------- | ||
16 | type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] // error | ||
| ^^^^^^^ | ||
| Type parameter ImTrait for type TypeLambda shadows the type defined by trait ImTrait in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:17:21 --------------------------------------------- | ||
17 | type PolyFun[A] = [ImTrait] => ImTrait => B // error | ||
| ^^^^^^^ | ||
| Type parameter ImTrait for type PolyFun shadows the type defined by trait ImTrait in object importTry | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:23:12 --------------------------------------------- | ||
23 | class Foo[T](t: T): // error class parameter shadows some other type | ||
| ^ | ||
| Type parameter T for class Foo shadows the type defined by type T in class B | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:27:15 --------------------------------------------- | ||
27 | def intType[List1](x: T) = x.toString() // error | ||
| ^^^^^ | ||
| Type parameter List1 for method intType shadows an explicitly renamed type : List1 | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:32:10 --------------------------------------------- | ||
32 | given [Int]: Ordering[Int]() // error | ||
| ^^^ | ||
| Type parameter Int for method given_Ordering_Int shadows the type defined by class Int in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:34:12 --------------------------------------------- | ||
34 | class C[M[List[_]]] // error List not renamed here | ||
| ^^^^^^^ | ||
| Type parameter List for class C shadows the type defined by type List in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:35:11 --------------------------------------------- | ||
35 | type E[M[Int[_]]] = Int // error | ||
| ^^^^^^ | ||
| Type parameter Int for type E shadows the type defined by class Int in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:37:14 --------------------------------------------- | ||
37 | def foo[N[M[List[_]]]] = // error | ||
| ^^^^^^^ | ||
| Type parameter List for method foo shadows the type defined by type List in package scala | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:40:11 --------------------------------------------- | ||
40 | type Z[ImClassR] = Int // error | ||
| ^^^^^^^^ | ||
| Type parameter ImClassR for type Z shadows an explicitly renamed type : ImClassR | ||
-- Error: tests/neg-custom-args/fatal-warnings/i17613b/i17613b.scala:41:18 --------------------------------------------- | ||
41 | class InnerCl[ImClassR] // error | ||
| ^^^^^^^^ | ||
| Type parameter ImClassR for class InnerCl shadows an explicitly renamed type : ImClassR |
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,44 @@ | ||
// scalac: -Xlint:type-parameter-shadow | ||
|
||
object i17613b: | ||
import importTry._ | ||
class B: | ||
type T = Int | ||
trait D | ||
|
||
def foobar[ImTrait](in: D) = in.toString // error | ||
type MySeq[ImTrait] = Seq[D] // error | ||
|
||
def foobar2[ImClass](in: D) = in.toString // error | ||
type MySeq2[ImClass] = Seq[D] // error | ||
|
||
given [A]: Ordering[Int]() | ||
type TypeLambda[A] = [ImTrait] =>> Map[ImTrait, B] // error | ||
type PolyFun[A] = [ImTrait] => ImTrait => B // error | ||
type MatchType[A] = A match { | ||
case String => Int | ||
case ImTrait => Boolean | ||
} | ||
|
||
class Foo[T](t: T): // error class parameter shadows some other type | ||
import scala.collection.immutable.{List => List1} | ||
def bar[List](w: T) = w.toString // no warning due to the explicit import renaming | ||
|
||
def intType[List1](x: T) = x.toString() // error | ||
|
||
type Y[List] = Int // no warning | ||
|
||
given [A]: Ordering[A]() | ||
given [Int]: Ordering[Int]() // error | ||
|
||
class C[M[List[_]]] // error List not renamed here | ||
type E[M[Int[_]]] = Int // error | ||
|
||
def foo[N[M[List[_]]]] = // error | ||
import importTry.{ImClass => ImClassR} | ||
def inner[ImClass] = // no warning | ||
type Z[ImClassR] = Int // error | ||
class InnerCl[ImClassR] // error | ||
5 | ||
|
||
def main(args: Array[String]) = println("Test for type parameter shadow") |
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 @@ | ||
object importTry: | ||
|
||
trait ImTrait | ||
|
||
class ImClass |