tc39 / proposal-private-methods

Private methods and getter/setters for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=1668
345 stars 37 forks source link

Weird coalescing behaviors #16

Closed jridgewell closed 7 years ago

jridgewell commented 7 years ago

Summarizing https://github.com/tc39/proposal-private-methods/commit/f719e009ba629527fa0e935ef2d5312e952f8806:

That means the following is fine:

class Test {
  get #field() {}
  set #field(v) {}
  get #field(v) {}
}

But this throws:

class Test {
  get #field() {}
  get #field() {}
  set #field(v) {}
}
littledan commented 7 years ago

Asserts in ECMAScript are not expected to fail on any program. They don't throw exceptions--if they are reached, that means the spec itself has a bug in it. See the definition of Assert.

Duplicate private method definitions are banned instead in Early Errors, the first of the two. If a private name is defined twice, it's an early error, unless it's a getter/setter pair.

You're right that we could add an additional assertion that other has [[Set]] and not [[Get]], or vice versa. I think this is a pretty minor editorial issue; PRs welcome. There are probably lots of asserts we could add.

littledan commented 7 years ago

I specified coalescing more specifically in this patch. Hopefully that should clear up any ambiguity.