-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Must call super constructor in derived class before accessing 'this' or returning from derived constructor #4744
Must call super constructor in derived class before accessing 'this' or returning from derived constructor #4744
Comments
🤔 Interesting. Hmm. This should be a TypeScript error, no? Since the [TypeScript playground showing both type error and runtime crash] I'd have thought that this type error is good and should be there. I.e. that the Stryker generates mutants that survive, but are not compiled by TypeScript FAQ covers this. If folks want their mutations to be type-error-free, they need to use a type checker plugin. No? |
Sorry for the confusion. Yes this would be a type error, but since Stryker adds But even in normal JS, this way of instrumenting is invalid, since this results in a runtime error. I'm wondering if this could be avoided somehow. So would there be a way to instrument this with mutants and have it be valid according to |
Indeed, this has nothing to do with the feature you've contributed to TS, it's just the way I discovered the bug, since I'm only programming in TS. |
Aha. This bug is TypeScript-specific. The problem is that TypeScript compiles it to this JS, which is invalid because if the export class UniqueKeyFailedError extends UnprocessableEntityException {
constructor(fields) {
this.fields = fields;
if (stryMutAct_9fa48("91")) {
{ }
}
else {
stryCov_9fa48("91");
const errorBody = stryMutAct_9fa48("92") ? {} : (stryCov_9fa48("92"), {
status: stryMutAct_9fa48("93") ? "" : (stryCov_9fa48("93"), 'uniqueness_failed'),
fields
});
super(errorBody);
}
}
} |
…super()` Support constructors in TypeScript that have some code before the `super()` call and have constructor properties or initialized class properties. In such cases, the block statement mutator is not applied. For more info, see #4744
Summary
Our friend "Must call super constructor in derived class before accessing 'this' or returning from derived constructor" is back.
Since TS 4.6 it is possible to call some code before
super()
. This is contributed by my friend @JoshuaKGoldberg 🙏However, this causes issues when Stryker tries to mutate that code. For example:
This code:
Gets instrumented as:
Which, after transpiling to JS, results in an optional
super
call, which is invalid, resulting in:This was previously a problem in #2474. We verified that the first call wasn't a call to
super()
. If so, we skip mutating that block. Let us do the same here, but now scan the entire block. Don't mutate beforesuper()
.@JoshuaKGoldberg if you have any better ideas, feel free to pitch in. Ideally, we would like to instrument that part of the code as well 🤷♀️
Reproduction example
See test/add-stryker branch in
rock-solid
The text was updated successfully, but these errors were encountered: