Scala-js: Run-time error in Scala.js-defined classes with multiple parameter lists and default args

Created on 7 Feb 2018  路  3Comments  路  Source: scala-js/scala-js

@js.annotation.ScalaJSDefined
class Foo(val default: Int)(
  val title: String,
  val description: js.UndefOr[String] = js.undefined
) extends js.Object

Trying to instantiate it

new Foo(42)(
  title = "failure"
)

fails with ERROR: prep0 is not defined.

It works if there's only one parameter list (not counting implicits) or no default args. The motivation for having 2 parameter lists is that the first parameter can be used to guide the type inference:

class Foo[T <: SomeType](val tpe: T)(
  val title: String,
  val default: T#ValueType,
  val description: js.UndefOr[String] = js.undefined
) extends js.Object

It won't work with a single parameter list.

Here's a ScalaFiddle with the code example: https://scalafiddle.io/sf/Twa9hbP/2

bug

All 3 comments

Thanks for the report.

Constructors of Scala.js-defined JS classes are touchy to start with, and default parameters in the presence of multiple parameter lists as well, so I'm not terribly surprised that things break if you throw them together.

We'll fix it for the next version.

Thanks for taking the time to narrow it down, I was lazy enough to simply open an issue for myself :-)
https://github.com/akka-js/akka.js/issues/69

Fixed in 1974810ba16a467370145d5247583b0cf998606c.

Was this page helpful?
0 / 5 - 0 ratings