Reproduce a crash in TypeScript 2.9 JS support.#25153
Closed
mprobst wants to merge 1 commit into
Closed
Conversation
If JavaScript code has both a `valueDeclaration` that is a binary
expression (e.g. property assignment), and additional declarations that are not, TypeScript gets confused and crashes in an attempted cast:
```
var CtorFunction = function() {
this.myField = 'a';
};
/** @type {string} */
CtorFunction.prototype.myField;
var x = new CtorFunction();
x.myField = 'b';
```
Leading to:
```
Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isBinaryExpression'.
at Object.cast (src/compiler/core.ts:1445:22)
at _loop_4 (src/compiler/checker.ts:4644:80)
at getWidenedTypeFromJSSpecialPropertyDeclarations (built/local/run.js:33366:31)
at getJSSpecialType (src/compiler/checker.ts:4982:21)
at getTypeOfVariableOrParameterOrProperty (src/compiler/checker.ts:4920:28)
at getTypeOfSymbol (src/compiler/checker.ts:5219:24)
at checkPropertyAccessExpressionOrQualifiedName (src/compiler/checker.ts:17285:53)
at checkPropertyAccessExpression (src/compiler/checker.ts:17238:20)
at checkExpressionWorker (src/compiler/checker.ts:20937:28)
at checkExpression (src/compiler/checker.ts:20878:44)
at checkBinaryLikeExpression (src/compiler/checker.ts:20350:28)
at checkBinaryExpression (src/compiler/checker.ts:20342:20)
at checkExpressionWorker (src/compiler/checker.ts:20976:28)
```
`getWidenedTypeFromJSSpecialPropertyDeclarations` iterates all declarations and then runs into the non-binary one.
Contributor
|
Should be covered by the test in #25170 |
Collaborator
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
If JavaScript code has both a
valueDeclarationthat is a binaryexpression (e.g. property assignment), and additional declarations that are not, TypeScript gets confused and crashes in an attempted cast:
Leading to:
getWidenedTypeFromJSSpecialPropertyDeclarationsiterates all declarations and then runs into the non-binary one.