[JS/TS/Python] Fix record/value type constructor including static backing fields as parameters#4405
Conversation
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
|
Something is not right in this PR because I definitely added tests and reverted the changes for Rust because it was breaking for that target. |
11e045a to
86197f8
Compare
86197f8 to
b7b43ce
Compare
|
@dbrattli It seems like the 4 new errors in Python type checking are caused by the line being too long.
How do we deal with that? Those lines are not the only ones too long in that file. Does it means we can just merge it and those new errors will be ignored in future run? |
|
@MangelMaxime That is strange. I though we ran ruff-formatting on the generated output. Let me have a look ... |
|
@MangelMaxime Check if this is needed for JS. I fixed it for Python: Record reflection info includes static backing fields When a record type has static let or static member val bindings, the backing fields for these statics are included in the reflection metadata alongside the actual instance fields. For example: type RecordWithStaticLet = The generated record_type(...) call reports fields [("_a", ...), ("init@...", ...), ("id", ...)] instead of just [("id", ...)]. This affects serialization, structural equality, and anything that uses reflection info at runtime. Fix: In transformRecordReflectionInfo, filter out static fields from ent.FSharpFields before generating the field list. The Python fix filters with fi.IsStatic in a Seq.choose. The equivalent change in Fable2Babel.fs would be at line 178: // Before // After This is the same pattern already applied to constructors in commit b7b43ce. |
…king fields as parameters
Filter static backing fields from record reflection metadata and generate ClassVar annotations on dataclasses so Pyright recognizes static attributes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Apply suggestion from @dbrattli
50c9bdc to
20758ba
Compare
|
Thank you I believe I indeed needed the same fix for JavaScript |

Summary
When a record or value type is augmented with
static letorstatic member val, the F# compiler generates static backing fields that appeared inent.FSharpFields. These were incorrectly included as constructor parameters, causing two distinct bugs:static letfields shift the index-basedargs[i]assignments in generated constructors, so{id = 1}could returnid = 0instead.static member valbacking fields (e.g.empty@fromstatic member val empty = ...) were treated as instance fields, causing all instances to share the same mutable backing store.Target changed
This PR is touching JavaScript, Python targets.
Other targets are left untouched because it was generating invalid code and I am no expert in those targets.