Skip to content

Fix #12621: Scala.js: Better error message for JS trait ctor param. #16811

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

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 @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions tests/neg-scalajs/js-trait-ctor-param.check
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/neg-scalajs/js-trait-ctor-param.scala
Original file line number Diff line number Diff line change
@@ -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