Skip to content

Commit 44126aa

Browse files
committed
Fix #18658: Handle varargs of generic types in JSExportsGen.
When extracting the type of a varargs parameter, we have to go back to before erasure. However, that gives us a non-erased type inside as well. We need to re-erase that type to get something sensible for the back-end.
1 parent d788ef2 commit 44126aa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/transform/sjs/JSSymUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ object JSSymUtils {
185185
val list =
186186
for ((name, info) <- paramNamesAndTypes) yield {
187187
val v =
188-
if (info.isRepeatedParam) Some(info.repeatedToSingle.widenDealias)
188+
if (info.isRepeatedParam) Some(TypeErasure.erasure(info.repeatedToSingle))
189189
else None
190190
name -> v
191191
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.scalajs.testsuite.jsinterop
2+
3+
import org.junit.Assert.*
4+
import org.junit.Test
5+
6+
import scala.scalajs.js
7+
import scala.scalajs.js.annotation.*
8+
9+
class NonNativeJSTypeTestScala3 {
10+
@Test
11+
def overloadWithVarargOfGenericType(): Unit = {
12+
class OverloadWithVarargOfGenericType extends js.Object {
13+
def overloaded(x: Int): Int = x
14+
def overloaded(xs: (Int, Int)*): Int = xs.size
15+
}
16+
17+
val obj = new OverloadWithVarargOfGenericType
18+
assertEquals(5, obj.overloaded(5))
19+
assertEquals(2, obj.overloaded((1, 2), (3, 4)))
20+
}
21+
}

0 commit comments

Comments
 (0)