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

Named export def inherited from traits crash the compiler #2440

Closed
sjrd opened this issue Jun 4, 2016 · 1 comment
Closed

Named export def inherited from traits crash the compiler #2440

sjrd opened this issue Jun 4, 2016 · 1 comment
Labels
0.6.x only Only applies to 0.6.x. N/A or already fixed in 1.x. bug Confirmed bug. Needs to be fixed. wontfix We decided not to fix this issue/not implement that feature request.

Comments

@sjrd
Copy link
Member

sjrd commented Jun 4, 2016

I found this while trying to strengthen the tests while fixing #2437. It turns out this does not even work in 2.11:

  @Test def name_exports_inherited_from_traits(): Unit = {
    import js.Dynamic.{literal => lit}

    trait FooNamedTrait {
      @JSExportNamed("bar1")
      def bar(x: Int, y: Int): Int = x + y

      @JSExportNamed("bar2")
      @JSExport
      def bar(x: Int = 1)(y: Int = x)(z: Int = y): Int = x + y + z
    }

    class BarNamedFromTrait extends FooNamedTrait

    val bar = (new BarNamedFromTrait).asInstanceOf[js.Dynamic]

    assertEquals(3, bar.bar1(lit(x = 1, y = 2)))
    if (hasCompliantAsInstanceOfs)
      assertThrows(classOf[Exception], bar.bar1(lit(x = 1))) // missing arg
    assertEquals(3, bar.bar2(lit()))
    assertEquals(6, bar.bar2(lit(x = 2)))
    assertEquals(5, bar.bar2(lit(y = 2)))
    assertEquals(4, bar.bar2(lit(y = 2, z = 1)))
    assertEquals(6, bar.bar(2))
    assertEquals(8, bar.bar(2,3))
  }

The stack trace points to this line:

scala.MatchError: org.scalajs.testsuite.jsinterop.ExportsTest$FooNamedTrait$1$class.$js$exported$meth|1(ExportsTest$BarNamedFromTrait$1.this, namedArgs) (of class scala.reflect.internal.Trees$Apply)
        at org.scalajs.core.compiler.GenJSExports$JSExportsPhase$class.genNamedExporterDef(GenJSExports.scala:126)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase.genNamedExporterDef(GenJSCode.scala:123)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase.org$scalajs$core$compiler$GenJSCode$JSCodePhase$$gen$1(GenJSCode.scala:390)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase$$anonfun$org$scalajs$core$compiler$GenJSCode$JSCodePhase$$gen$1$1.apply(GenJSCode.scala:377)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase$$anonfun$org$scalajs$core$compiler$GenJSCode$JSCodePhase$$gen$1$1.apply(GenJSCode.scala:377)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase.org$scalajs$core$compiler$GenJSCode$JSCodePhase$$gen$1(GenJSCode.scala:377)
        at org.scalajs.core.compiler.GenJSCode$JSCodePhase.genClass(GenJSCode.scala:404)
        ...
@sjrd sjrd added the bug Confirmed bug. Needs to be fixed. label Jun 4, 2016
@sjrd sjrd added the wontfix We decided not to fix this issue/not implement that feature request. label Jul 11, 2016
@sjrd
Copy link
Member Author

sjrd commented Jul 11, 2016

Fixing this appears to be non-trivial, and since we've deprecated @JSExportNamed, I'll close this as won't fix.

@sjrd sjrd closed this as completed Jul 11, 2016
@sjrd sjrd added the 0.6.x only Only applies to 0.6.x. N/A or already fixed in 1.x. label Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6.x only Only applies to 0.6.x. N/A or already fixed in 1.x. bug Confirmed bug. Needs to be fixed. wontfix We decided not to fix this issue/not implement that feature request.
Projects
None yet
Development

No branches or pull requests

2 participants