Emit diagnostic when redeclaring a local name, fixes #452

This commit is contained in:
dcode 2019-02-03 13:37:32 +01:00
parent 4829f3a3e4
commit c95c0f5fbe

View File

@ -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));