Three error cases for private name semantic errors:
- shadowing (the nested classes case). See also suggested error message.
- accessibility violation
- name not found
(1) and (2) are special cases of (3)
Confusing note on terminology: in the semantics, '#foo' is the description for a private name, what a Muggle would call a "spelling" and a philosophyer would call an "orthography." From a semantic point of view, the private name itself (
#foo
) is unforgeable and cannot be written down, even thought it's clear exactly where the private name node in the syntax is.
Rough algorithm for generating the most accurate error message for leftHandSide.#foo
:
- go up the lexical scopes, looking for a private name description '#foo'
- let privateName = resolvePrivateNameDescription('#foo')
- if leftHandSode[[privateName]]
- OK, no error
- else // privateName doesn't exist on the object, just need to figure out which error to report
- keep going up the lexical scopes
- if there is a scope such that leftHandSide[[resolvePrivateNameDescription('#foo')]]:
- error 1: shadowing. (See the Chrome Canary nested classes example)
- else (no scope with a private name by the description '#foo'):
- check if the lhs is an instance of a class that does have a private name for the description '#foo'
- if yes: error 2: accessibility violation
- else: generic error: 3. name not found
- check if the lhs is an instance of a class that does have a private name for the description '#foo'