Fix NaN-valued enum members creating distinct literal types#3932
Open
Copilot wants to merge 3 commits into
Open
Fix NaN-valued enum members creating distinct literal types#3932Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/4d642ea9-d310-4a99-b4f0-21b5bbc1eb13 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
In Go, NaN != NaN for map key comparisons, causing each NaN-valued enum member to get a distinct type. Fix by caching NaN types separately from the map-based caches in both getNumberLiteralType and getEnumLiteralType. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/4d642ea9-d310-4a99-b4f0-21b5bbc1eb13 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix distinct enum literal type error for NaN values
Fix NaN-valued enum members creating distinct literal types
May 16, 2026
jakebailey
approved these changes
May 16, 2026
Member
jakebailey
left a comment
There was a problem hiding this comment.
Yep, this is what I expected the fix to be
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Go-specific bug where NaN-valued enum members produced distinct literal types because Go map lookups always miss on NaN keys (IEEE 754 NaN != NaN). The fix routes NaN values through dedicated cache fields, ensuring NaN members within the same enum share a literal type (matching TypeScript's Map behavior which treats NaN keys as equal).
Changes:
- Added dedicated
nanTypefield to bypass map lookup for plain numeric NaN literals. - Added
enumNaNLiteralTypes map[*ast.Symbol]*Typekeyed by enum symbol so NaN enum members share a type per enum. - Added compiler test and removed obsolete
enumConstantMembers.types.diffbaseline (now converged with TypeScript).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/checker/checker.go | Add nanType and enumNaNLiteralTypes caches; special-case NaN in getNumberLiteralType and getEnumLiteralType. |
| testdata/tests/cases/compiler/enumNaNValues.ts | New regression test covering NaN members within and across enums. |
| testdata/baselines/reference/compiler/enumNaNValues.* | New baselines for the regression test. |
| testdata/baselines/reference/compiler/enumAutoIncrementValue.types | Baseline update reflecting converged literal type identity. |
| testdata/baselines/reference/submodule/conformance/enumConstantMembers.types | Submodule baseline now matches TS reference. |
| testdata/baselines/reference/submodule/conformance/enumConstantMembers.types.diff | Removed (convergence with TypeScript). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Go maps use IEEE 754 equality for key comparison, where NaN != NaN. This means map lookups with NaN keys always miss, causing each NaN-valued enum member to get a distinct literal type.
TypeScript's JS
Maptreats NaN === NaN for key purposes, so this isn't an issue there.Changes
getNumberLiteralType: Added a dedicatednanType *Typefield to bypass themap[jsnum.Number]*Typelookup for NaN valuesgetEnumLiteralType: AddedenumNaNLiteralTypes map[*ast.Symbol]*Typekeyed by enum symbol, so NaN members within the same enum share a type while different enums remain distinctenumConstantMembers.types.diffbaseline (convergence with TypeScript)