Skip to content

Commit b9a02cd

Browse files
committed
Fix #12621: Scala.js: Better error message for JS trait ctor param.
JS traits cannot have constructor params any more than they can have concrete term members. This improves the error message in that case.
1 parent e751f51 commit b9a02cd

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala

+3
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,9 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
888888
report.error("A non-native JS trait cannot contain private members", tree)
889889
} else if (sym.is(Lazy)) {
890890
report.error("A non-native JS trait cannot contain lazy vals", tree)
891+
} else if (sym.is(ParamAccessor)) {
892+
// #12621
893+
report.error("A non-native JS trait cannot have constructor parameters", tree)
891894
} else if (!sym.is(Deferred)) {
892895
/* Tell the back-end not to emit this thing. In fact, this only
893896
* matters for mixed-in members created from this member.

Diff for: tests/neg-scalajs/js-trait-ctor-param.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg-scalajs/js-trait-ctor-param.scala:9:34 -------------------------------------------------------------
2+
9 |trait NonNativeBagHolderTrait(val bag: Bag) extends js.Any // error
3+
| ^^^^^^^^^^^^
4+
| A non-native JS trait cannot have constructor parameters

Diff for: tests/neg-scalajs/js-trait-ctor-param.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.scalajs.js
2+
import scala.scalajs.js.annotation.*
3+
4+
@js.native
5+
trait Bag extends js.Any {
6+
val str: String
7+
}
8+
9+
trait NonNativeBagHolderTrait(val bag: Bag) extends js.Any // error

0 commit comments

Comments
 (0)