Skip to content

Commit c47249d

Browse files
committed
Fix scala#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 c47249d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ object JSSymUtils {
181181
def paramNamesAndTypes(using Context): List[(Names.TermName, Type)] =
182182
sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten)
183183

184+
def reerase(tpe: Type): Type =
185+
TypeErasure.erasure(tpe)
186+
184187
val paramInfosAtElimRepeated = atPhase(elimRepeatedPhase) {
185188
val list =
186189
for ((name, info) <- paramNamesAndTypes) yield {
187190
val v =
188-
if (info.isRepeatedParam) Some(info.repeatedToSingle.widenDealias)
191+
if (info.isRepeatedParam) Some(reerase(info.repeatedToSingle.widenDealias))
189192
else None
190193
name -> v
191194
}
@@ -206,7 +209,7 @@ object JSSymUtils {
206209
new JSParamInfo(info, repeated = true)
207210

208211
case Some(None) =>
209-
val info = paramInfosAtElimEVT.getOrElse(paramName, paramInfoNow)
212+
val info = paramInfosAtElimEVT.get(paramName).fold(paramInfoNow)(reerase(_))
210213
new JSParamInfo(info)
211214
}
212215
}
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)