diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala index d934dc179989..8a430991e378 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala @@ -888,6 +888,9 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP report.error("A non-native JS trait cannot contain private members", tree) } else if (sym.is(Lazy)) { report.error("A non-native JS trait cannot contain lazy vals", tree) + } else if (sym.is(ParamAccessor)) { + // #12621 + report.error("A non-native JS trait cannot have constructor parameters", tree) } else if (!sym.is(Deferred)) { /* Tell the back-end not to emit this thing. In fact, this only * matters for mixed-in members created from this member. diff --git a/tests/neg-scalajs/js-trait-ctor-param.check b/tests/neg-scalajs/js-trait-ctor-param.check new file mode 100644 index 000000000000..bc5296b3c76f --- /dev/null +++ b/tests/neg-scalajs/js-trait-ctor-param.check @@ -0,0 +1,4 @@ +-- Error: tests/neg-scalajs/js-trait-ctor-param.scala:9:34 ------------------------------------------------------------- +9 |trait NonNativeBagHolderTrait(val bag: Bag) extends js.Any // error + | ^^^^^^^^^^^^ + | A non-native JS trait cannot have constructor parameters diff --git a/tests/neg-scalajs/js-trait-ctor-param.scala b/tests/neg-scalajs/js-trait-ctor-param.scala new file mode 100644 index 000000000000..c907b0d9b606 --- /dev/null +++ b/tests/neg-scalajs/js-trait-ctor-param.scala @@ -0,0 +1,9 @@ +import scala.scalajs.js +import scala.scalajs.js.annotation.* + +@js.native +trait Bag extends js.Any { + val str: String +} + +trait NonNativeBagHolderTrait(val bag: Bag) extends js.Any // error