Closed Bug 1275240 Opened 8 years ago Closed 8 years ago

Redeclaration of formal parameter with lexical binding should be SyntaxError

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: arai, Assigned: arai)

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

|function f(a) { let a }| should throw SyntaxError, but we throw TypeError

js> function f(a) { let a }
typein:1:20 TypeError: redeclaration of formal parameter a:
typein:1:20 function f(a) { let a }
typein:1:20 ....................^

https://tc39.github.io/ecma262/#sec-function-definitions-static-semantics-early-errors
>  * It is a Syntax Error if any element of the BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of FunctionBody.
fwiw, with strict mode warnings, this code also throws a TypeError warning and not a SyntaxError warning:
  function f(arg) { var arg } 

TypeError: variable arg redeclares argument 

That's JSMSG_VAR_HIDES_ARG and it appears quite often according to current Telemetry data.
Keywords: dev-doc-needed
(In reply to Florian Scholz [:fscholz] (MDN) from comment #2)
> fwiw, with strict mode warnings, this code also throws a TypeError warning
> and not a SyntaxError warning:
>   function f(arg) { var arg } 
> 
> TypeError: variable arg redeclares argument 
> 
> That's JSMSG_VAR_HIDES_ARG and it appears quite often according to current
> Telemetry data.

redeclaration with "var" is different thing than let/const.
not sure if that warning is specced thing.
will check it :)
Summary: Redeclaration of formal parameter should be SyntaxError → Redeclaration of formal parameter with lexical binding should be SyntaxError
the type of warning is not specced, so at least JSMSG_VAR_HIDES_ARG is not something we should change its type here.
https://hg.mozilla.org/integration/mozilla-inbound/rev/97d4fa9f099b14a98d4242f1c73507beb1f70081
Bug 1275240 - Fix the type of parameter redeclaration from TypeError to SyntaxError. r=shu
https://hg.mozilla.org/mozilla-central/rev/97d4fa9f099b
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.