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 #16173: SJS: Fix the detection of inferred types of = js.native. #16184

Merged
merged 1 commit into from
Oct 14, 2022

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Oct 14, 2022

No description provided.

@Kordyjan Kordyjan linked an issue Oct 14, 2022 that may be closed by this pull request
@smarter
Copy link
Member

smarter commented Oct 14, 2022

I'm not convinced this is the right fix, the code mentioned in the issue is

      if (tree.tpt.span.isSynthetic)
        report.error(i"The type of ${tree.name} must be explicitly specified because it is JS native.", tree)

If you want to check if the type was inferred, you should be able to do tree.tpt.isInstanceOf[InferredTypeTree] instead.

@sjrd sjrd force-pushed the sjs-native-with-literal-type branch from a293cf6 to 488aa27 Compare October 14, 2022 12:36
@sjrd sjrd changed the title Fix #16173: Give a non-synthetic span to singleton literal types. Fix #16173: SJS: Fix the detection of inferred types of = js.native. Oct 14, 2022
@sjrd
Copy link
Member Author

sjrd commented Oct 14, 2022

That is indeed a better fix, thanks. I've updated the PR.

That said, is it still not wrong that literal type trees get a synthetic span? 🤔

@smarter
Copy link
Member

smarter commented Oct 14, 2022

I guess you could do override def span = ref.span in SingletonTypeTree since it really represents the same thing as the tree it wraps?

@@ -981,7 +981,7 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP

// Check that the resul type was explicitly specified
Copy link
Member

Choose a reason for hiding this comment

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

drive-by typo suggestion:

Suggested change
// Check that the resul type was explicitly specified
// Check that the result type was explicitly specified

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed.

…tive`.

Use `tpt.isInstanceOf[InferredTypeTree]` instead of relying on the
span being synthetic.
@sjrd sjrd force-pushed the sjs-native-with-literal-type branch from 488aa27 to 63f96f0 Compare October 14, 2022 13:04
@sjrd sjrd requested a review from smarter October 14, 2022 14:36
@sjrd sjrd merged commit c9c95d4 into scala:main Oct 14, 2022
@sjrd sjrd deleted the sjs-native-with-literal-type branch October 14, 2022 15:13
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 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.

Scala.js: Literal types not accepted for JS native methods/values
3 participants