Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #18658: Handle varargs of generic types in JSExportsGen. #18659

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ object JSSymUtils {
val list =
for ((name, info) <- paramNamesAndTypes) yield {
val v =
if (info.isRepeatedParam) Some(info.repeatedToSingle.widenDealias)
if (info.isRepeatedParam) Some(TypeErasure.erasure(info.repeatedToSingle))
else None
name -> v
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.scalajs.testsuite.jsinterop

import org.junit.Assert.*
import org.junit.Test

import scala.scalajs.js
import scala.scalajs.js.annotation.*

class NonNativeJSTypeTestScala3 {
import NonNativeJSTypeTestScala3.*

@Test
def overloadWithVarargOfGenericType(): Unit = {
class OverloadWithVarargOfGenericType extends js.Object {
def overloaded(x: Int): Int = x
def overloaded(xs: (Int, Int)*): Int = xs.size
}

val obj = new OverloadWithVarargOfGenericType
assertEquals(5, obj.overloaded(5))
assertEquals(1, obj.overloaded((5, 6)))
assertEquals(2, obj.overloaded((1, 2), (3, 4)))
}

@Test
def overloadWithVarargOfValueClass(): Unit = {
class OverloadWithVarargOfValueClass extends js.Object {
def overloaded(x: Int): Int = x
def overloaded(xs: VC*): Int = xs.size
}

val obj = new OverloadWithVarargOfValueClass
assertEquals(5, obj.overloaded(5))
assertEquals(1, obj.overloaded(new VC(5)))
assertEquals(2, obj.overloaded(new VC(5), new VC(6)))
}

@Test
def overloadWithVarargOfGenericValueClass(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test opaque-type aliases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

class OverloadWithVarargOfGenericValueClass extends js.Object {
def overloaded(x: Int): Int = x
def overloaded(xs: GenVC[Int]*): Int = xs.size
}

val obj = new OverloadWithVarargOfGenericValueClass
assertEquals(5, obj.overloaded(5))
assertEquals(1, obj.overloaded(new GenVC(5)))
assertEquals(2, obj.overloaded(new GenVC(5), new GenVC(6)))
}

@Test
def overloadWithVarargOfOpaqueTypeAlias(): Unit = {
import OpaqueContainer.*

class OverloadWithVarargOfOpaqueTypeAlias extends js.Object {
def overloaded(x: String): Int = x.toInt
def overloaded(xs: OpaqueInt*): Int = xs.size
}

val obj = new OverloadWithVarargOfOpaqueTypeAlias
assertEquals(5, obj.overloaded("5"))
assertEquals(1, obj.overloaded(fromInt(5)))
assertEquals(2, obj.overloaded(fromInt(5), fromInt(6)))
}
}

object NonNativeJSTypeTestScala3 {
final class VC(val x: Int) extends AnyVal

final class GenVC[T](val x: T) extends AnyVal

object OpaqueContainer {
opaque type OpaqueInt = Int

def fromInt(x: Int): OpaqueInt = x
def toInt(x: OpaqueInt): Int = x
}
}
Loading