Skip to content

[JS] Fix equality of PrimitiveKClassImpl (KT-87307)#6510

Open
Sergej Jaskiewicz (broadwaylamb) wants to merge 5 commits into
masterfrom
rr/broadwaylamb/js-long-kclass-eq
Open

[JS] Fix equality of PrimitiveKClassImpl (KT-87307)#6510
Sergej Jaskiewicz (broadwaylamb) wants to merge 5 commits into
masterfrom
rr/broadwaylamb/js-long-kclass-eq

Conversation

@broadwaylamb

@broadwaylamb Sergej Jaskiewicz (broadwaylamb) commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

KT-87307

Make PrimitiveKClassImpl comparable with any KClassImpl, not just PrimitiveKClassImpl. This fixes a regression that was introduced in 6d14904.

@kodee-bot

kodee-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

~~This MR fixes the regression, but the root cause is not yet documented as required by the guideline
Please update the commit message to include a description of the root cause, using one of the following prefixes: ^RCA:, #RCA:.

This will allow our automation to copy the RCA into the issue comments and automatically apply the root-cause-defined tag.~~

@kotlin-safemerge

kotlin-safemerge Bot commented Jul 2, 2026

Copy link
Copy Markdown

@broadwaylamb Sergej Jaskiewicz (broadwaylamb) force-pushed the rr/broadwaylamb/js-long-kclass-eq branch from e356ec3 to ecceaf4 Compare July 2, 2026 17:00
This identifier is replaced with the actual backend name at source
preprocessing time, before the test file is fed to the compiler.
Make `PrimitiveKClassImpl` comparable with any `KClassImpl`, not just
`PrimitiveKClassImpl`. This fixes a regression that was introduced in
6d14904.

^KT-87307 Fixed

^RCA:
**Root cause:** In the commit 6d14904
we started lowering
`Long::class` to `kotlin.reflect.js.internal.PrimitiveClasses.longClass`
unconditionally, not just when compiling `Long` to `BigInt`
`PrimitiveClasses.longClass` has the type `PrimitiveKClassImpl`,
and `42L::class` would have the type `SimpleKClassImpl` when compiling
`Long` as a regular class, so comparing them would always yield `false`,
because of how equality was defined in `PrimitiveKClassImpl`.
We had a test for this, but it didn't catch the regression
because the relevant logic of computing `42L::class` was optimized away
into just `Long::class` by the compiler, which made the test useless.

**Preventive steps taken:** the test was improved to be more robust.

**Future steps:** raise awareness about this class of issues among
compiler engineers, so that they write more robust tests,
e.g. by wrapping literals into blackhole-like functions that are
guaranteed to not be optimized away.

**Additional notes:** As mentioned, there already was an autotest, but
the compiler has outsmarted us.
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.

1 participant