Skip to content

Fix #5287: Handle JS objects in MatchError.getMessage().#5288

Merged
sjrd merged 2 commits intoscala-js:mainfrom
sjrd:fix-match-error-js-object
Jan 3, 2026
Merged

Fix #5287: Handle JS objects in MatchError.getMessage().#5288
sjrd merged 2 commits intoscala-js:mainfrom
sjrd:fix-match-error-js-object

Conversation

@sjrd
Copy link
Copy Markdown
Member

@sjrd sjrd commented Dec 30, 2025

No description provided.

Copied as of v2.13.17 of the upstream repo.
@sjrd sjrd requested a review from gzm0 December 30, 2025 10:05
@sjrd sjrd force-pushed the fix-match-error-js-object branch from f24700c to 27dbc1c Compare December 30, 2025 13:38
Copy link
Copy Markdown
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

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

IIUC to fix the immediate problem, this is a good approach.

Would it make sense to add some discussion about adjusting getClass?

IIUC at this point, it feels odd that getClass returns null, rather than a "special" jl.Class (in the spirit of: if it links, it's correct). Of course, changing this, would be quite the breaking change, likely for a lot of SJS code itself.

Maybe, we should add a tracking issue for 2.x to re-consider?

@sjrd
Copy link
Copy Markdown
Member Author

sjrd commented Jan 3, 2026

I briefly thought about that. It's definitely 2.x material: it's a run-time breaking change of something that's definitely working as intended. We have tests for that behavior. (I thought it was listed in https://www.scala-js.org/doc/semantics.html, but apparently not. I'll need to add that.)

I don't think it breaks the spirit of "if it links, it works". To get a null, you need to manipulate JS-specific things. The JavaDoc cannot specify that behavior, so we get to specify it ourselves. Another perspective: there is no Scala/JVM code that, when compiled and linked with Scala.js, will give you null.

But there's no denying that there can be some undesirable consequences, like this particular issue. We could revisit.

@sjrd sjrd merged commit 6c436f3 into scala-js:main Jan 3, 2026
4 checks passed
@sjrd sjrd deleted the fix-match-error-js-object branch January 3, 2026 10:50
@gzm0
Copy link
Copy Markdown
Contributor

gzm0 commented Jan 3, 2026

I don't think it breaks the spirit of "if it links, it works". To get a null, you need to manipulate JS-specific things. The JavaDoc cannot specify that behavior, so we get to specify it ourselves. Another perspective: there is no Scala/JVM code that, when compiled and linked with Scala.js, will give you null.

I'm not sure I fully agree with this TBH. I think mostly because "manipulating JS-specific things" is a global property: when targeting Scala.js, you have to assume JS specific things are manipulated. As a result, breaking a base JVM assumption (getClass returns non-null) significantly weakens the cross-compilation promise (FWIW: I think this issue illustrates this very nicely).

In any case, I agree the discussion is somewhat moot for the current compatibility line. I'll just file the 2.x issue.

sjrd added a commit to sjrd/dotty that referenced this pull request Jan 5, 2026
sjrd added a commit to scala/scala3 that referenced this pull request Jan 5, 2026
WojciechMazur pushed a commit to scala/scala3 that referenced this pull request Jan 13, 2026
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.

2 participants