From c95c0f5fbe7ae37ff1dd3e4997c675e67eb5a925 Mon Sep 17 00:00:00 2001 From: dcode Date: Sun, 3 Feb 2019 13:37:32 +0100 Subject: [PATCH] Emit diagnostic when redeclaring a local name, fixes #452 --- src/compiler.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 9e8b8678..0b28eb67 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2244,7 +2244,14 @@ export class Compiler extends DiagnosticEmitter { ) { // here: not top-level local = flow.addScopedLocal(type, name, false, declaration); // reports } else { - local = currentFunction.addLocal(type, name, declaration); // reports + if (currentFunction.flow.getScopedLocal(name)) { + this.error( + DiagnosticCode.Duplicate_identifier_0, + declaration.name.range, name + ); + continue; + } + local = currentFunction.addLocal(type, name, declaration); } if (initExpr) { initializers.push(this.compileAssignmentWithValue(declaration.name, initExpr));