Redeclaration of formal parameter with lexical binding should be SyntaxError

RESOLVED FIXED in Firefox 49

Status

()

defect
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: arai, Assigned: arai)

Tracking

({dev-doc-complete})

Trunk
mozilla49
Points:
---

Firefox Tracking Flags

(firefox49 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
|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
(Assignee)

Comment 3

3 years ago
(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
(Assignee)

Comment 4

3 years ago
the type of warning is not specced, so at least JSMSG_VAR_HIDES_ARG is not something we should change its type here.
(Assignee)

Comment 6

3 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/97d4fa9f099b14a98d4242f1c73507beb1f70081
Bug 1275240 - Fix the type of parameter redeclaration from TypeError to SyntaxError. r=shu

Comment 7

3 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/97d4fa9f099b
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.