Skip to content

Commit 6aea560

Browse files
committed
Make compiler tests compatible with Scala 2.13.2+.
Starting from 2.13.2, method types are printed with a `: ` to separate the parameter lists from the result types. This changes some of our error messages.
1 parent 553ed11 commit 6aea560

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

compiler/src/test/scala/org/scalajs/core/compiler/test/JSExportTest.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
package org.scalajs.core.compiler.test
1414

1515
import org.scalajs.core.compiler.test.util._
16-
import org.junit.Test
16+
import org.scalajs.core.compiler.test.util.VersionDependentMessages.methodSig
1717

1818
import org.junit.Assume._
19+
import org.junit.Test
1920

2021
// scalastyle:off line.size.limit
2122

@@ -267,10 +268,10 @@ class JSExportTest extends DirectTest with TestHelpers {
267268
def foo(x: Int*) = x
268269
}
269270
""" hasErrors
270-
"""
271+
s"""
271272
|newSource1.scala:7: error: Cannot disambiguate overloads for exported method foo with types
272-
| (x: Int, ys: Seq)Object
273-
| (x: Seq)Object
273+
| ${methodSig("(x: Int, ys: Seq)", "Object")}
274+
| ${methodSig("(x: Seq)", "Object")}
274275
| @JSExport
275276
| ^
276277
"""
@@ -283,10 +284,10 @@ class JSExportTest extends DirectTest with TestHelpers {
283284
def foo(x: String*) = x
284285
}
285286
""" hasErrors
286-
"""
287+
s"""
287288
|newSource1.scala:6: error: Cannot disambiguate overloads for exported method foo with types
288-
| (x: Int)Object
289-
| (x: Seq)Object
289+
| ${methodSig("(x: Int)", "Object")}
290+
| ${methodSig("(x: Seq)", "Object")}
290291
| @JSExport
291292
| ^
292293
"""
@@ -1637,10 +1638,10 @@ class JSExportTest extends DirectTest with TestHelpers {
16371638
def bar(x: Int): Int = x + 1
16381639
}
16391640
""" hasErrors
1640-
"""
1641+
s"""
16411642
|newSource1.scala:10: error: Cannot disambiguate overloads for exported method foo with types
1642-
| (x: Int)Int
1643-
| (x: Int)Int
1643+
| ${methodSig("(x: Int)", "Int")}
1644+
| ${methodSig("(x: Int)", "Int")}
16441645
| def bar(x: Int): Int = x + 1
16451646
| ^
16461647
"""
@@ -1679,10 +1680,10 @@ class JSExportTest extends DirectTest with TestHelpers {
16791680
def bar_=(v: Int): Unit = ()
16801681
}
16811682
""" hasErrors
1682-
"""
1683+
s"""
16831684
|newSource1.scala:10: error: Cannot disambiguate overloads for exported method foo with types
1684-
| (v: Int)Unit
1685-
| (v: Int)Unit
1685+
| ${methodSig("(v: Int)", "Unit")}
1686+
| ${methodSig("(v: Int)", "Unit")}
16861687
| def bar_=(v: Int): Unit = ()
16871688
| ^
16881689
"""

compiler/src/test/scala/org/scalajs/core/compiler/test/ScalaJSDefinedTest.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.scalajs.core.compiler.test
1414

1515
import org.scalajs.core.compiler.test.util._
16+
import org.scalajs.core.compiler.test.util.VersionDependentMessages.methodSig
1617

1718
import org.junit.Test
1819
import org.junit.Ignore
@@ -156,10 +157,10 @@ class ScalaJSDefinedTest extends DirectTest with TestHelpers {
156157
def bar(): Int = 24
157158
}
158159
""" hasErrors
159-
"""
160+
s"""
160161
|newSource1.scala:9: error: Cannot disambiguate overloads for method bar with types
161-
| ()Int
162-
| ()Int
162+
| ${methodSig("()", "Int")}
163+
| ${methodSig("()", "Int")}
163164
| def bar(): Int = 24
164165
| ^
165166
"""
@@ -172,10 +173,10 @@ class ScalaJSDefinedTest extends DirectTest with TestHelpers {
172173
def foo(): Int = 42
173174
}
174175
""" hasErrors
175-
"""
176+
s"""
176177
|newSource1.scala:9: error: Cannot disambiguate overloads for method bar with types
177-
| ()Int
178-
| ()Int
178+
| ${methodSig("()", "Int")}
179+
| ${methodSig("()", "Int")}
179180
| def foo(): Int = 42
180181
| ^
181182
"""
@@ -190,10 +191,10 @@ class ScalaJSDefinedTest extends DirectTest with TestHelpers {
190191
def bar(): Int = 24
191192
}
192193
""" hasErrors
193-
"""
194+
s"""
194195
|newSource1.scala:11: error: Cannot disambiguate overloads for method bar with types
195-
| ()Int
196-
| ()Int
196+
| ${methodSig("()", "Int")}
197+
| ${methodSig("()", "Int")}
197198
| def bar(): Int = 24
198199
| ^
199200
"""
@@ -210,10 +211,10 @@ class ScalaJSDefinedTest extends DirectTest with TestHelpers {
210211
def bar(): Int = 24
211212
}
212213
""" hasErrors
213-
"""
214+
s"""
214215
|newSource1.scala:13: error: Cannot disambiguate overloads for method bar with types
215-
| ()Int
216-
| ()Int
216+
| ${methodSig("()", "Int")}
217+
| ${methodSig("()", "Int")}
217218
| def bar(): Int = 24
218219
| ^
219220
"""
@@ -232,10 +233,10 @@ class ScalaJSDefinedTest extends DirectTest with TestHelpers {
232233
def foo(): Int = 42
233234
}
234235
""" hasErrors
235-
"""
236+
s"""
236237
|newSource1.scala:14: error: Cannot disambiguate overloads for method foo with types
237-
| (x: Int)Int
238-
| (x: Int)Int
238+
| ${methodSig("(x: Int)", "Int")}
239+
| ${methodSig("(x: Int)", "Int")}
239240
| class Bar extends Foo {
240241
| ^
241242
"""
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Scala.js (https://www.scala-js.org/)
3+
*
4+
* Copyright EPFL.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (https://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package org.scalajs.core.compiler.test.util
14+
15+
object VersionDependentMessages {
16+
private val scalaVersion = scala.util.Properties.versionNumberString
17+
18+
private val usesColonInMethodSig = {
19+
!scalaVersion.startsWith("2.10.") &&
20+
!scalaVersion.startsWith("2.11.") &&
21+
!scalaVersion.startsWith("2.12.") &&
22+
scalaVersion != "2.13.0" &&
23+
scalaVersion != "2.13.1"
24+
}
25+
26+
def methodSig(params: String, resultType: String): String =
27+
if (usesColonInMethodSig) params + ": " + resultType
28+
else params + resultType
29+
}

0 commit comments

Comments
 (0)