Skip to content

Fix crash caused by cyclic defaults #30532

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

Merged
merged 1 commit into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5474,9 +5474,6 @@ namespace ts {
}
return type;
}
if (declaration.kind === SyntaxKind.ExportAssignment) {
return widenTypeForVariableLikeDeclaration(checkExpressionCached((<ExportAssignment>declaration).expression), declaration);
}

// Handle variable, parameter or property
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
Expand All @@ -5487,7 +5484,10 @@ namespace ts {
return reportCircularityError(symbol);
}
let type: Type | undefined;
if (isInJSFile(declaration) &&
if (declaration.kind === SyntaxKind.ExportAssignment) {
type = widenTypeForVariableLikeDeclaration(checkExpressionCached((<ExportAssignment>declaration).expression), declaration);
}
else if (isInJSFile(declaration) &&
(isCallExpression(declaration) || isBinaryExpression(declaration) || isPropertyAccessExpression(declaration) && isBinaryExpression(declaration.parent))) {
type = getWidenedTypeFromAssignmentDeclaration(symbol);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/QSpinner.js(3,1): error TS7022: 'default' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.


==== tests/cases/compiler/QSpinner.js (1 errors) ====
import DefaultSpinner from './QSpinner'

export default {
~~~~~~~~~~~~~~~~
mixins: [DefaultSpinner],
~~~~~~~~~~~~~~~~~~~~~~~~~~~
name: 'QSpinner'
~~~~~~~~~~~~~~~~~~
}
~
!!! error TS7022: 'default' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

17 changes: 17 additions & 0 deletions tests/baselines/reference/selfReferentialDefaultNoStackOverflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [QSpinner.js]
import DefaultSpinner from './QSpinner'

export default {
mixins: [DefaultSpinner],
name: 'QSpinner'
}


//// [QSpinner.js]
"use strict";
exports.__esModule = true;
var QSpinner_1 = require("./QSpinner");
exports["default"] = {
mixins: [QSpinner_1["default"]],
name: 'QSpinner'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/QSpinner.js ===
import DefaultSpinner from './QSpinner'
>DefaultSpinner : Symbol(DefaultSpinner, Decl(QSpinner.js, 0, 6))

export default {
mixins: [DefaultSpinner],
>mixins : Symbol(mixins, Decl(QSpinner.js, 2, 16))
>DefaultSpinner : Symbol(DefaultSpinner, Decl(QSpinner.js, 0, 6))

name: 'QSpinner'
>name : Symbol(name, Decl(QSpinner.js, 3, 27))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/QSpinner.js ===
import DefaultSpinner from './QSpinner'
>DefaultSpinner : any

export default {
>{ mixins: [DefaultSpinner], name: 'QSpinner'} : { mixins: any[]; name: string; }

mixins: [DefaultSpinner],
>mixins : any[]
>[DefaultSpinner] : any[]
>DefaultSpinner : any

name: 'QSpinner'
>name : string
>'QSpinner' : "QSpinner"
}

11 changes: 11 additions & 0 deletions tests/cases/compiler/selfReferentialDefaultNoStackOverflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @allowJs: true
// @checkJs: true
// @strict: true
// @outDir: ./out
// @filename: QSpinner.js
import DefaultSpinner from './QSpinner'

export default {
mixins: [DefaultSpinner],
name: 'QSpinner'
}