Skip to content

Conversation

@Shanks0224
Copy link
Contributor

@Shanks0224 Shanks0224 commented Oct 10, 2023

When the method of the base class is overridden, the 'belongingClass' property of this method is tampered with into its subclass.

@Shanks0224
Copy link
Contributor Author

Shanks0224 commented Oct 10, 2023

Currently, the ‘belongedClass‘ property is mostly used in the specialization logic of the constructor of a generic class.
Since there is no override relationship between the constructor of the subclass and the constructor of the base class, the ‘belongedClass‘ of the base class constructor will not be tampered with.
So this bug does not affect the results of test cases.

@Shanks0224 Shanks0224 changed the title fix: the 'belongedClass' property of the overridden method has been tampered with its subclass fix: the 'belongedClass' property of the overridden method has been tampered with Oct 10, 2023
src/type.ts Outdated
addMethod(classMethod: TsClassFunc): void {
classMethod.type.isMethod = true;
classMethod.type.belongedClass = this;
// the subclass inherits the method of the base class and should not modify the belongedClass of the base class method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// the subclass inherits the method of the base class and should not modify the belongedClass of the base class method.
// when sub class inherits the method of the base class, it should not modify the `belongedClass`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

infc.addMethod(method);
infc.addMethod({
name: method.name,
type: method.type.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why here use a copy type of method?

Copy link
Contributor Author

@Shanks0224 Shanks0224 Oct 11, 2023

Choose a reason for hiding this comment

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

If copy is not used, the method inherited from the base class in the subclass represents the same object as the base class method.
When modifying the property value of a method in a subclass, it will affect the method of the base class.

Copy link
Contributor

@kylo5aby kylo5aby left a comment

Choose a reason for hiding this comment

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

LGTM

@xujuntwt95329 xujuntwt95329 merged commit c41a7f1 into web-devkits:main Oct 12, 2023
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.

3 participants