Skip to content

Reproduce a crash in TypeScript 2.9 JS support.#25153

Closed
mprobst wants to merge 1 commit into
microsoft:masterfrom
mprobst:crash-prop-nonbinary
Closed

Reproduce a crash in TypeScript 2.9 JS support.#25153
mprobst wants to merge 1 commit into
microsoft:masterfrom
mprobst:crash-prop-nonbinary

Conversation

@mprobst
Copy link
Copy Markdown
Contributor

@mprobst mprobst commented Jun 22, 2018

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.

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.
@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Jun 25, 2018

Should be covered by the test in #25170

@mhegazy mhegazy closed this Jun 25, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
@typescript-bot
Copy link
Copy Markdown
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants