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

Missing guard for duplicate class method declaration #1083

Open
ceremcem opened this issue Mar 17, 2019 · 1 comment
Open

Missing guard for duplicate class method declaration #1083

ceremcem opened this issue Mar 17, 2019 · 1 comment
Labels

Comments

@ceremcem
Copy link

Following class definition:

class a
  hello: ->
  there: -> 
  hello: -> 2

is compiled to following Javascript code without any exception thrown:

var a;
a = (function(){
  a.displayName = 'a';
  var prototype = a.prototype, constructor = a;
  a.prototype.hello = function(){};
  a.prototype.there = function(){};
  a.prototype.hello = function(){
    return 2;
  };
  function a(){}
  return a;
}());

...which doesn't prevent us erroneous re-definition of a method. I would expect a proper error, like duplicate property definition in an object:

a =
  hello: ->
  there: -> 
  hello: -> 2

# => duplicate property "hello" on line 4

Would you consider adding such a guard in class definitions?

@rhendric
Copy link
Collaborator

That makes sense to me. I can't think of any reason why it should be one way for classes but another way for objects.

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

2 participants