Skip to content

Commit a528afe

Browse files
authored
Merge pull request #482 from ucode-lang/fix/strict-redeclare-error-position
compiler: report strict redeclarations at the redeclaring name
2 parents a219b9e + b5ce443 commit a528afe

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎compiler.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ uc_compiler_declare_local(uc_compiler_t *compiler, uc_value_t *name, bool consta
957957
}
958958

959959
if (uc_compiler_is_strict(compiler)) {
960-
uc_compiler_syntax_error(compiler, 0, "Variable '%s' redeclared", str2);
960+
uc_compiler_syntax_error(compiler, compiler->parser->prev.pos,
961+
"Variable '%s' redeclared", str2);
961962

962963
return -1;
963964
}

‎tests/custom/00_syntax/29_function_forward_declarations‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,27 @@ In line 4, byte 5:
271271
foo++;
272272
%}
273273
-- End --
274+
275+
276+
13. In strict mode, a regular function may not be declared twice in the
277+
same scope.
278+
279+
-- Expect stderr --
280+
Syntax error: Variable 'foo' redeclared
281+
In line 6, byte 11:
282+
283+
` function foo() { return 2; }`
284+
Near here ---^
285+
286+
287+
-- End --
288+
289+
-- Testcase --
290+
{%
291+
"use strict";
292+
293+
function foo() { return 1; }
294+
295+
function foo() { return 2; }
296+
%}
297+
-- End --

0 commit comments

Comments
 (0)