Skip to content

fix(js/ts/python): pass explicit ctor args to primary base - #5247

Draft
MangelMaxime wants to merge 16 commits into
mainfrom
fix/explicit-ctor-primary-base
Draft

MangelMaxime wants to merge 16 commits into
mainfrom
fix/explicit-ctor-primary-base

Conversation

@MangelMaxime

@MangelMaxime MangelMaxime commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #5227.

On JS, TS and Python, then blocks and new() as x now also work in an explicit constructor whose base class has a primary constructor.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 33
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 11 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved constructor-generation defects can produce invalid parameter lists, corrupt forwarded arguments, and break initialization order, causing parse errors and incorrect runtime behavior.

7 open issues
What changed in this PR

Addresses #5227 by forwarding explicit constructor arguments to primary-constructor bases in Fable’s JavaScript, TypeScript, and Python targets, preserving inheritance and base initialization.

Changes:

  • Adds primary-base argument forwarding and rejects unsupported multi-level inheritance chains.
  • Updates ParamArray forwarding in JS/TS and Python constructor wrappers.
  • Adds regression tests for inherited members, type tests, generics, naming collisions, optional arguments, and ParamArray arguments.
File Description
tests/​Python/​TestType.fs Adds Python constructor-inheritance regression tests.
tests/​Js/​Main/​TypeTests.fs Adds shared JS/TS constructor-inheritance regression tests.
src/​Fable.Transforms/​Python/​Fable2Python.Transforms.fs Converts constructor ParamArrays and forwards variadic arguments.
src/​Fable.Transforms/​FSharp2Fable.Util.fs Builds primary-base arguments and reports unsupported inheritance chains.
src/​Fable.Transforms/​FSharp2Fable.fs Forwards base arguments during explicit constructor lowering.
src/​Fable.Transforms/​Babel/​Fable2Babel.fs Spreads ParamArray arguments in exposed constructor wrappers.

Review effort: Balanced

Comment thread src/Fable.Transforms/FSharp2Fable.fs Resolved
Comment thread src/Fable.Transforms/FSharp2Fable.fs Resolved
@MangelMaxime
MangelMaxime force-pushed the fix/explicit-ctor-primary-base branch from 8f8777b to afe1e98 Compare November 5, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

match param.Type with
| Fable.Option(genArg, isStruct) ->
Fable.Value(Fable.NewOption(None, genArg, isStruct), None)
| t -> Replacements.Api.defaultof com ctx None t
Comment on lines +1871 to +1874
if
ownArgs |> List.exists (canHaveSideEffects com)
|| bindings |> List.exists (snd >> canHaveSideEffects com)
then

This branch has not been deployed

No deployments
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.

Explicit constructor inheriting a class with a primary constructor drops the base

2 participants