Commit 5c036cd7 authored by littledan's avatar littledan Committed by Commit bot

Improve error message for duplicate parameters

Duplicate parameters are banned both overall in strict mode and also
in arrow functions. Our error message for both cases blamed strict
mode, which is confusing. This patch fixes the message to point to
arrow functions as a possible source as well.

R=wingo, adamk
LOG=N

Review URL: https://codereview.chromium.org/1236863008

Cr-Commit-Position: refs/heads/master@{#29662}
parent 9d6ab46a
...@@ -157,8 +157,7 @@ class ExpressionClassifier { ...@@ -157,8 +157,7 @@ class ExpressionClassifier {
if (!is_valid_formal_parameter_list_without_duplicates()) return; if (!is_valid_formal_parameter_list_without_duplicates()) return;
invalid_productions_ |= DistinctFormalParametersProduction; invalid_productions_ |= DistinctFormalParametersProduction;
duplicate_formal_parameter_error_.location = loc; duplicate_formal_parameter_error_.location = loc;
duplicate_formal_parameter_error_.message = duplicate_formal_parameter_error_.message = MessageTemplate::kParamDupe;
MessageTemplate::kStrictParamDupe;
duplicate_formal_parameter_error_.arg = nullptr; duplicate_formal_parameter_error_.arg = nullptr;
} }
......
...@@ -297,8 +297,6 @@ class CallSite { ...@@ -297,8 +297,6 @@ class CallSite {
T(ConstructorIsGenerator, "Class constructor may not be a generator") \ T(ConstructorIsGenerator, "Class constructor may not be a generator") \
T(DerivedConstructorReturn, \ T(DerivedConstructorReturn, \
"Derived constructors may only return object or undefined") \ "Derived constructors may only return object or undefined") \
T(DuplicateArrawFunFormalParam, \
"Arrow function may not have duplicate parameter names") \
T(DuplicateConstructor, "A class may only have one constructor") \ T(DuplicateConstructor, "A class may only have one constructor") \
T(DuplicateExport, "Duplicate export of '%'") \ T(DuplicateExport, "Duplicate export of '%'") \
T(DuplicateProto, \ T(DuplicateProto, \
...@@ -335,6 +333,7 @@ class CallSite { ...@@ -335,6 +333,7 @@ class CallSite {
T(ParamAfterRest, "Rest parameter must be last formal parameter") \ T(ParamAfterRest, "Rest parameter must be last formal parameter") \
T(BadSetterRestParameter, \ T(BadSetterRestParameter, \
"Setter function argument must not be a rest parameter") \ "Setter function argument must not be a rest parameter") \
T(ParamDupe, "Duplicate parameter name not allowed in this context") \
T(ParenthesisInArgString, "Function arg string contains parenthesis") \ T(ParenthesisInArgString, "Function arg string contains parenthesis") \
T(SingleFunctionLiteral, "Single function literal required") \ T(SingleFunctionLiteral, "Single function literal required") \
T(SloppyLexical, \ T(SloppyLexical, \
...@@ -346,8 +345,6 @@ class CallSite { ...@@ -346,8 +345,6 @@ class CallSite {
"In strict mode code, functions can only be declared at top level or " \ "In strict mode code, functions can only be declared at top level or " \
"immediately within another function.") \ "immediately within another function.") \
T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \ T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
T(StrictParamDupe, \
"Strict mode function may not have duplicate parameter names") \
T(StrictWith, "Strict mode code may not include a with statement") \ T(StrictWith, "Strict mode code may not include a with statement") \
T(StrongArguments, \ T(StrongArguments, \
"In strong mode, 'arguments' is deprecated, use '...args' instead") \ "In strong mode, 'arguments' is deprecated, use '...args' instead") \
......
...@@ -2057,7 +2057,7 @@ Variable* Parser::Declare(Declaration* declaration, ...@@ -2057,7 +2057,7 @@ Variable* Parser::Declare(Declaration* declaration,
if (declaration_kind == DeclarationDescriptor::NORMAL) { if (declaration_kind == DeclarationDescriptor::NORMAL) {
ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name); ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name);
} else { } else {
ParserTraits::ReportMessage(MessageTemplate::kStrictParamDupe); ParserTraits::ReportMessage(MessageTemplate::kParamDupe);
} }
*ok = false; *ok = false;
return nullptr; return nullptr;
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-arrow-functions
(b, a, a, d) => a
*%(basename)s:7: SyntaxError: Duplicate parameter name not allowed in this context
(b, a, a, d) => a
^
SyntaxError: Duplicate parameter name not allowed in this context
*%(basename)s:6: SyntaxError: Strict mode function may not have duplicate parameter names *%(basename)s:6: SyntaxError: Duplicate parameter name not allowed in this context
function foo(b, a, a, d) { return a } function foo(b, a, a, d) { return a }
^ ^
SyntaxError: Strict mode function may not have duplicate parameter names SyntaxError: Duplicate parameter name not allowed in this context
...@@ -69,8 +69,8 @@ PASS (function (){'use strict'; try{}catch(eval){}}) threw exception SyntaxError ...@@ -69,8 +69,8 @@ PASS (function (){'use strict'; try{}catch(eval){}}) threw exception SyntaxError
PASS (function(){(function (){'use strict'; try{}catch(eval){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode. PASS (function(){(function (){'use strict'; try{}catch(eval){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function (){'use strict'; try{}catch(arguments){}}) threw exception SyntaxError: Unexpected eval or arguments in strict mode. PASS (function (){'use strict'; try{}catch(arguments){}}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function(){(function (){'use strict'; try{}catch(arguments){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode. PASS (function(){(function (){'use strict'; try{}catch(arguments){}})}) threw exception SyntaxError: Unexpected eval or arguments in strict mode.
PASS (function (a, a){'use strict';}) threw exception SyntaxError: Strict mode function may not have duplicate parameter names. PASS (function (a, a){'use strict';}) threw exception SyntaxError: Duplicate parameter name not allowed in this context.
PASS (function(){(function (a, a){'use strict';})}) threw exception SyntaxError: Strict mode function may not have duplicate parameter names. PASS (function(){(function (a, a){'use strict';})}) threw exception SyntaxError: Duplicate parameter name not allowed in this context.
PASS (function (a){'use strict'; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode.. PASS (function (a){'use strict'; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS (function(){(function (a){'use strict'; delete a;})()}) threw exception SyntaxError: Delete of an unqualified identifier in strict mode.. PASS (function(){(function (a){'use strict'; delete a;})()}) threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
PASS (function (){'use strict'; var a; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode.. PASS (function (){'use strict'; var a; delete a;})() threw exception SyntaxError: Delete of an unqualified identifier in strict mode..
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment