Skip to content

Instantly share code, notes, and snippets.

@mheiber
Last active September 7, 2018 10:33
Show Gist options
  • Save mheiber/03ca6b200fdd2121d24674f19fbc5db7 to your computer and use it in GitHub Desktop.
Save mheiber/03ca6b200fdd2121d24674f19fbc5db7 to your computer and use it in GitHub Desktop.
Error cases for private names

Three error cases for private name semantic errors:

  1. shadowing (the nested classes case). See also suggested error message.
  2. accessibility violation
  3. 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')]]:
    • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment