gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.31k stars 156 forks source link

Missing guard for duplicate class method declaration #1083

Open ceremcem opened 5 years ago

ceremcem commented 5 years ago

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 commented 5 years ago

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.