Repository navigation
[patch] Call super() first in a JavaScript derived class's constructor - #156
Merged
Merged
Conversation
The JavaScript generator wrote `class Circle extends Shape` but never wrote a `super(...)` call in the constructor, so every `new Circle()` threw ReferenceError before it could assign to `this`. C++ and C# call the base's default constructor implicitly, so the same AST worked in those targets. A constructor in a class with a BaseType now opens with `super();`. An initialiser named after the base (the C++ `: Base(args)` idiom) supplies the argument as `super(value);` rather than being assigned to `this.Base`. Fixes #103 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N47Hdpq8iSMutiKdDS81pa
The super() call pushed GenerateMethod's cognitive complexity to 16, over SonarCloud's limit of 15 (S3776). The initialiser loop, including skipping the initialiser already passed to super, now lives in WriteInitialiserAssignments. Output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N47Hdpq8iSMutiKdDS81pa
|
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.



Fixes #103
Problem
JavaScriptGeneratorwroteclass Circle extends Shapebut never wrote asuper(...)call in the constructor. Everynew Circle()therefore threwReferenceError: Must call super constructor in derived class before accessing 'this'.... C++ and C# call the base's default constructor implicitly, so the same AST worked in those targets.Change
GenerateMethodnow takes the enclosing class'sBaseType. A constructor in a derived class opens withsuper();, before anythis.x = ...initialiser assignment.: Base(args)idiom. It is now emitted assuper(value);, not asthis.Shape = value;. This was the issue's second acceptance bullet.supercall.Tests
New tests in
JavaScriptGeneratorTests:super();comes beforethis.radius = radius;.super(radius);, with nothis.Shape.super.2 shape. It is inconclusive when node is not on the path.With the generator change reverted, the three derived-class tests fail. The full suite passes: 1058/1058.
🤖 Generated with Claude Code
https://claude.ai/code/session_01N47Hdpq8iSMutiKdDS81pa
Generated by Claude Code