Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect repeat argument names at compile time #809

Closed
rudi-c opened this issue Oct 9, 2014 · 7 comments
Closed

Detect repeat argument names at compile time #809

rudi-c opened this issue Oct 9, 2014 · 7 comments

Comments

@rudi-c
Copy link

rudi-c commented Oct 9, 2014

The following code

sum x x = x + x
mySum = sum 1 2

Generates the error

Uncaught SyntaxError: Strict mode function may not have duplicate parameter names

Which is good, except that the error message appears only in the console. Instead, the webpage only shows

Cannot read property 'make' of undefined
    Open the developer console for more details.

Which makes debugging really confusing.

@evancz evancz added this to the simple looking bugs milestone Aug 6, 2015
@evancz evancz changed the title Duplicate parameter generates incorrect error message Detect repeat argument names at compile time Aug 6, 2015
@evancz evancz added the bug label Aug 6, 2015
@thSoft
Copy link
Contributor

thSoft commented Oct 19, 2015

This has bit me multiple times! Also happens when declaring a local variable with the same name as an argument:

update action model =
  let result =
        (model, effects)
      (updatedSubmodel, effects) =
        Subcomponent.update action model.submodel
      model = -- should be updatedModel
        { model | submodel <- updatedSubmodel }
  in result

@jvoigtlaender
Copy link
Contributor

Are the previous two comments really placed correctly in this issue here? Don't they belong to #829 / #1018 instead?

Look at the opening comment of this issue. It is about a very specific situation that is not what you (@thSoft and @Apanatshka) are talking about here.

@thSoft
Copy link
Contributor

thSoft commented Oct 20, 2015

Sorry, you're right, @jvoigtlaender. Should I delete my comment?

@mgold
Copy link
Contributor

mgold commented Oct 20, 2015

As for the original issue, I remember seeing something similar. Can someone please verify that the issue exists in the 0.16 alpha?

@mgold
Copy link
Contributor

mgold commented Nov 14, 2015

It still exists in 0.16-alpha3. In the repl:

> sum x x = x + x
/<PATH SNIPPED>/repl-temp-000.js:6039
   var sum = F2(function (x,x) {    return x + x;});
                            ^

SyntaxError: Duplicate parameter name not allowed in this context
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:136:18)
    at node.js:972:3

@yblein
Copy link
Contributor

yblein commented Feb 14, 2016

Also the following code

sum x (x, y) = x + y
mySum = sum 1 (2, 3)

does not produce an error. Instead, mySum is equal to 5.
I guess this kind of multiple binding should be prevented too?

@mgold
Copy link
Contributor

mgold commented Feb 14, 2016

Yes, there is no sensible way to interpret that definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants