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

Fix #12572: Ignore default accessor bridges in non-native JS classes. #12657

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented May 31, 2021

They are not emitted, and they are excluded when looking up the default getter to call.


Who would like to review this? Anyone familiar with default getters?

…sses.

They are not emitted, and they are excluded when looking up the
default getter to call.
Comment on lines +1075 to +1076
* because they call another default accessor, making their entire body an
* <undefined-param> that cannot be eliminated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's <undefined-param> ? I see the test cases set the default value to = js.undefined but what if I use a different default value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The right-hand-side of a default value is irrelevant. As soon as there is a default value, where = js.undefined, = 42 or = js.native, that parameter will be an <undefined-param>. <undefined-param>'s are markers that are always eliminated at compile-time, and replaced by no argument (because you can do that in JS). That is done at
https://github.com/lampepfl/dotty/blob/0d1d47a8fde5226b81376f5ff09512be17abaa0c/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala#L3764-L3776

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so should the compiler disallow a default value that is not exactly js.undefined ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it shouldn't. It wouldn't work when the type of the parameter is Int, for example. Also, an actual value can have valuable documentation purposes. It's been allowed for 8 years in Scala.js for Scala 2, so we can't change that.

@smarter smarter merged commit 37c9584 into scala:master Jun 22, 2021
@smarter smarter deleted the sjs-default-accessors-bridges-in-non-native-js-classes branch June 22, 2021 19:21
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants