Skip to content

fix: #2204, #2211 resolve loop #2264

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 8 commits into from
Jul 23, 2022
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
18 changes: 18 additions & 0 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,9 @@ export class Resolver extends DiagnosticEmitter {
return null;
}

/** resolving expressions */
private resolvingExpressions: Set<Expression> = new Set();

/** Resolves an expression to its static type. */
resolveExpression(
/** The expression to resolve. */
Expand All @@ -1006,6 +1009,21 @@ export class Resolver extends DiagnosticEmitter {
ctxType: Type = Type.auto,
/** How to proceed with eventual diagnostics. */
reportMode: ReportMode = ReportMode.REPORT
): Type | null {
const resolvingExpressions = this.resolvingExpressions;
if (resolvingExpressions.has(node)) return null;
resolvingExpressions.add(node);
const resolved = this.doResolveExpression(node, ctxFlow, ctxType, reportMode);
resolvingExpressions.delete(node);
return resolved;
}

/** Resolves an expression to its static type. (may cause stack overflow) */
private doResolveExpression(
node: Expression,
ctxFlow: Flow,
ctxType: Type = Type.auto,
reportMode: ReportMode = ReportMode.REPORT
): Type | null {
while (node.kind == NodeKind.PARENTHESIZED) { // skip
node = (<ParenthesizedExpression>node).expression;
Expand Down
10 changes: 10 additions & 0 deletions tests/compiler/avoid-resolve-loop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"asc_flags": [
],
"stderr": [
"AS225: Expression cannot be represented by a type.",
"TS2448: Variable 'avoid-resolve-loop/e' used before its declaration.",
"TS2322: Type 'void' is not assignable to type '<auto>'.",
"AS225: Expression cannot be represented by a type."
]
}
4 changes: 4 additions & 0 deletions tests/compiler/avoid-resolve-loop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let a = a[0];

let e = e;
typeof [e];