Skip to content

Commit 0bcade9

Browse files
committed
Update checkfiles for overriding errors
1 parent 4e591de commit 0bcade9

10 files changed

+143
-35
lines changed

tests/neg/abstract-givens.check

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,34 @@
33
| ^
44
|instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined
55
-- [E164] Declaration Error: tests/neg/abstract-givens.scala:8:8 -------------------------------------------------------
6+
error overriding given instance y in trait T of type (using x$1: Int): String;
7+
given instance y of type (using x$1: Int): String cannot override final member given instance y in trait T
8+
3 | given y(using Int): String = summon[Int].toString
9+
| -
10+
| the overridden given instance is here
11+
4 | given z[T](using T): List[T]
12+
5 |
13+
6 |object Test extends T:
14+
7 | given x: Int = 22
615
8 | given y(using Int): String = summon[Int].toString * 22 // error
716
| ^
8-
| error overriding given instance y in trait T of type (using x$1: Int): String;
9-
| given instance y of type (using x$1: Int): String cannot override final member given instance y in trait T
17+
| the overriding given instance cannot override final member given instance y in trait T
18+
1019
-- [E164] Declaration Error: tests/neg/abstract-givens.scala:9:8 -------------------------------------------------------
20+
error overriding given instance z in trait T² of type [T](using x$1: T): List[T];
21+
given instance z of type [T](using x$1: T): Seq[T] has incompatible type
22+
23+
where: T is a type variable
24+
T² is a trait in the empty package
25+
4 | given z[T](using T): List[T]
26+
| -
27+
| the overridden given instance is here
28+
5 |
29+
6 |object Test extends T:
30+
7 | given x: Int = 22
31+
8 | given y(using Int): String = summon[Int].toString * 22 // error
1132
9 | given z[T](using T): Seq[T] = List(summon[T]) // error
1233
| ^
13-
| error overriding given instance z in trait T² of type [T](using x$1: T): List[T];
14-
| given instance z of type [T](using x$1: T): Seq[T] has incompatible type
15-
|
16-
| where: T is a type variable
17-
| T² is a trait in the empty package
34+
| the overriding given instance has incompatible type
1835
|
1936
| longer explanation available when compiling with `-explain`

tests/neg/exports2.check

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
-- [E164] Declaration Error: tests/neg/exports2.scala:8:11 -------------------------------------------------------------
2+
error overriding method f in trait B of type => String;
3+
method f of type => String cannot override since it comes from an export
4+
5 | def f: String = "abc"
5+
| -
6+
| the overridden method is here
7+
6 |
8+
7 |object C extends B:
29
8 | export A._ // error
310
| ^
4-
| error overriding method f in trait B of type => String;
5-
| method f of type => String cannot override since it comes from an export
11+
| the overriding method cannot override since it comes from an export
12+

tests/neg/harmonize.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ object Test {
7979
val a4 = ArrayBuffer(1.0f, 1L)
8080
val b4: ArrayBuffer[Double] = a4 // error: no widening
8181
val a5 = ArrayBuffer(1.0f, 1L, f())
82-
val b5: ArrayBuffer[Float | Long | Int] = a5
82+
val b5: ArrayBuffer[Float | Long | Int] = a5 // error: no widening
8383
val a6 = ArrayBuffer(1.0f, 1234567890)
84-
val b6: ArrayBuffer[Float | Int] = a6
84+
val b6: ArrayBuffer[Float | Int] = a6 // error: no widening
8585

8686
def totalDuration(results: List[Long], cond: Boolean): Long =
8787
results.map(r => if (cond) r else 0).sum

tests/neg/i14415.check

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
-- [E164] Declaration Error: tests/neg/i14415.scala:21:6 ---------------------------------------------------------------
2-
21 |class X extends E with D // error
3-
| ^
4-
| error overriding method m in trait C of type (a: Int): Int;
5-
| method m in trait D of type (a: Int): Int needs `abstract override` modifiers
2+
error overriding method m in trait C of type (a: Int): Int;
3+
method m in trait D of type (a: Int): Int needs `abstract override` modifiers
4+
10 | abstract override def m(a:Int):Int = { return super.m(a); }
5+
| -
6+
| the overridden method is here
7+
11 |}
8+
12 |
9+
13 |trait D extends B with C {
10+
14 | override def m(a:Int):Int = { return super.m(a); }
11+
| ^
12+
| the overriding method needs `abstract override` modifiers
13+

tests/neg/i23474.check

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99
| class Z needs to be abstract, since var comment_=(x$1: String): Unit in trait Comment is not defined
1010
| (Note that an abstract var requires a setter in addition to the getter)
1111
-- [E164] Declaration Error: tests/neg/i23474.scala:11:15 --------------------------------------------------------------
12+
error overriding variable comment in trait Comment of type String;
13+
method comment of type => String cannot override a mutable variable
14+
2 | var comment: String
15+
| -
16+
| the overridden variable is here
17+
3 |}
18+
4 |
19+
5 |case class Y(val comment: String) extends Comment // error
20+
6 |
21+
7 |class Z extends Comment: // error
22+
8 | val comment: String = ""
23+
9 |
24+
10 |class X extends Comment: // error
1225
11 | override def comment: String = "" // error
1326
| ^
14-
| error overriding variable comment in trait Comment of type String;
15-
| method comment of type => String cannot override a mutable variable
27+
| the overriding method cannot override a mutable variable
28+
1629
-- Error: tests/neg/i23474.scala:10:6 ----------------------------------------------------------------------------------
1730
10 |class X extends Comment: // error
1831
| ^
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
-- [E164] Declaration Error: tests/neg/override-scala2-macro.scala:2:22 ------------------------------------------------
2-
2 | override inline def f[A >: Any](args: A*): String = ??? // error
3-
| ^
4-
|error overriding method f in class StringContext of type [A >: Any](args: Seq[A]): String;
5-
| method f of type [A >: Any](args: Seq[A]): String cannot be used here - only Scala-2 macros can override Scala-2 macros
2+
error overriding method f in class StringContext of type [A >: Any](args: Seq[A]): String;
3+
method f of type [A >: Any](args: Seq[A]): String cannot be used here - only Scala-2 macros can override Scala-2 macros
4+
... library/src/scala/StringContext.scala
5+
197 | def f[A >: Any](args: A*): String = macro ??? // fasttracked to scala.tools.reflect.FormatInterpolator::interpolateF
6+
| -
7+
| the overridden method is here
8+
... tests/neg/override-scala2-macro.scala
9+
2 | override inline def f[A >: Any](args: A*): String = ??? // error
10+
| ^
11+
| the overriding method cannot be used here - only Scala-2 macros can override Scala-2 macros
12+
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
-- [E164] Declaration Error: tests/neg/parent-refinement-access.scala:6:6 ----------------------------------------------
2+
error overriding value x in trait Year2 of type Int;
3+
value x in trait Gen of type Any has weaker access privileges; it should be public
4+
(Note that value x in trait Year2 of type Int is abstract,
5+
and is therefore overridden by concrete value x in trait Gen of type Any)
6+
4 | private[Gen] val x: Any = ()
7+
| ^
8+
| the overriding value has weaker access privileges; it should be public
9+
5 |
210
6 |trait Year2(private[Year2] val value: Int) extends (Gen { val x: Int }) // error
3-
| ^
4-
| error overriding value x in trait Year2 of type Int;
5-
| value x in trait Gen of type Any has weaker access privileges; it should be public
6-
| (Note that value x in trait Year2 of type Int is abstract,
7-
| and is therefore overridden by concrete value x in trait Gen of type Any)
11+
| -
12+
| the overridden value is here
13+
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
-- [E164] Declaration Error: tests/neg/publicInBinaryOverride.scala:8:15 -----------------------------------------------
2+
error overriding method f in class A of type (): Unit;
3+
method f of type (): Unit also needs to be declared with @publicInBinary
4+
4 | @publicInBinary def f(): Unit = ()
5+
| -
6+
| the overridden method is here
7+
5 | @publicInBinary def g(): Unit = ()
8+
6 |
9+
7 |class B extends A:
210
8 | override def f(): Unit = () // error
311
| ^
4-
| error overriding method f in class A of type (): Unit;
5-
| method f of type (): Unit also needs to be declared with @publicInBinary
12+
| the overriding method also needs to be declared with @publicInBinary
13+

tests/neg/targetName-override.check

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
11
-- [E164] Declaration Error: tests/neg/targetName-override.scala:16:35 -------------------------------------------------
2+
error overriding method foo in class Alpha of type (): Int;
3+
method foo of type (): Int should not have a @targetName annotation since the overridden member hasn't one either
4+
6 | def foo() = 1
5+
| -
6+
| the overridden method is here
7+
7 |
8+
8 | @targetName("foo1") def foo(x: T): T
9+
9 |
10+
10 | @targetName("append") def ++ (xs: Alpha[T]): Alpha[T] = this
11+
11 |
12+
12 |}
13+
13 |
14+
14 |class Beta extends Alpha[String] { // error: needs to be abstract
15+
15 |
216
16 | @targetName("foo1") override def foo() = 1 // error: should not have a target name
317
| ^
4-
|error overriding method foo in class Alpha of type (): Int;
5-
| method foo of type (): Int should not have a @targetName annotation since the overridden member hasn't one either
18+
| the overriding method should not have a @targetName annotation since the overridden member hasn't one either
19+
620
-- [E164] Declaration Error: tests/neg/targetName-override.scala:18:25 -------------------------------------------------
21+
error overriding method foo in class Alpha of type (x: String): String;
22+
method foo of type (x: String): String has a different target name annotation; it should be @targetName(foo1)
23+
8 | @targetName("foo1") def foo(x: T): T
24+
| -
25+
| the overridden method is here
26+
9 |
27+
10 | @targetName("append") def ++ (xs: Alpha[T]): Alpha[T] = this
28+
11 |
29+
12 |}
30+
13 |
31+
14 |class Beta extends Alpha[String] { // error: needs to be abstract
32+
15 |
33+
16 | @targetName("foo1") override def foo() = 1 // error: should not have a target name
34+
17 |
735
18 | @targetName("baz") def foo(x: String): String = x ++ x // error: has a different target name annotation
836
| ^
9-
| error overriding method foo in class Alpha of type (x: String): String;
10-
| method foo of type (x: String): String has a different target name annotation; it should be @targetName(foo1)
37+
| the overriding method has a different target name annotation; it should be @targetName(foo1)
38+
1139
-- [E164] Declaration Error: tests/neg/targetName-override.scala:20:15 -------------------------------------------------
40+
error overriding method ++ in class Alpha of type (xs: Alpha[String]): Alpha[String];
41+
method ++ of type (xs: Alpha[String]): Alpha[String] misses a target name annotation @targetName(append)
42+
10 | @targetName("append") def ++ (xs: Alpha[T]): Alpha[T] = this
43+
| -
44+
| the overridden method is here
45+
11 |
46+
12 |}
47+
13 |
48+
14 |class Beta extends Alpha[String] { // error: needs to be abstract
49+
15 |
50+
16 | @targetName("foo1") override def foo() = 1 // error: should not have a target name
51+
17 |
52+
18 | @targetName("baz") def foo(x: String): String = x ++ x // error: has a different target name annotation
53+
19 |
1254
20 | override def ++ (xs: Alpha[String]): Alpha[String] = this // error: misses a targetname annotation
1355
| ^
14-
| error overriding method ++ in class Alpha of type (xs: Alpha[String]): Alpha[String];
15-
| method ++ of type (xs: Alpha[String]): Alpha[String] misses a target name annotation @targetName(append)
56+
| the overriding method misses a target name annotation @targetName(append)
57+
1658
-- Error: tests/neg/targetName-override.scala:14:6 ---------------------------------------------------------------------
1759
14 |class Beta extends Alpha[String] { // error: needs to be abstract
1860
| ^^^^

tests/warn/matchable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def foo[T](x: T): Matchable =
1313
List(x) match
1414
case (x: Int) :: Nil => // warn: should not be scrutinized
1515
println("int")
16-
x
16+
x // warn
1717
case List(x: String) => // warn: should not be scrutinized
1818
println("string")
1919
x

0 commit comments

Comments
 (0)