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

fix(sem): issues with method-call syntax in templates #1298

Merged
merged 14 commits into from
May 6, 2024

Commits on May 3, 2024

  1. semtempl: simpler nkExprEqExpr|nkExprColonExpr handling

    Instead of going through the `semTemplBody` indirection, directly check
    whether the name part can be substituted with a template parameter.
    This also prevents non-gensyms from being bound in the name position.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    287b5ad View commit details
    Browse the repository at this point in the history
  2. semtempl: split nkAccQuoted handling from nkDotExpr

    Using a dedicated branch requires less conditionals, and prepares for
    changing the dot expression handling. Except for the edge case where a
    quoted symbol choice (which is nonsense anyway) is inserted into a
    template body by a macro, the behaviour stays the same.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    1a26052 View commit details
    Browse the repository at this point in the history
  3. semtempl: clean up nkDotExpr handling

    Move the not-a-qualified-symbol handling into the `if s.isNil` branch.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    0b03eb7 View commit details
    Browse the repository at this point in the history
  4. semtempl: always bind gensyms in field positions

    This lifts the restriction that a gensym'ed symbol cannot be used in a
    field access position. However, at the moment, it also causes symbols
    such as `skVar` symbols to be bound there, which is incorrect.
    
    Since gensyms don't reach into `semTemplSymbol` anymore, all
    conditionals including them become false and are thus obsolete.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    1d08c4a View commit details
    Browse the repository at this point in the history
  5. semtempl: only consider a subset of symbols in field positions

    Only routine symbols and type / generic parameter symbols are
    considered in field access positions, addressing the problem that
    symbols of, e.g., locals blocked other symbols.
    
    Symbol binding in generics for dot expressions works similar, with
    the differences that:
    * types and generic parameters are not considered there
    * a *closed* symbol choice is forced, instead of an *open* one
    
    Using an open symbol choice is wrong (it violates the specification),
    but is required for backwards compatibility.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    fd240c1 View commit details
    Browse the repository at this point in the history
  6. semtempl: remove noGenSym

    It's never incremented and is always zero.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    b9ffc79 View commit details
    Browse the repository at this point in the history
  7. semtempl: fix symChoice

    * rename `isField` to the more imperative `noGenSyms`
    * fix gensyms being added to the symbol choice, even if disabled (the
      flags of `s` were tested, not those of `a`)
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    40d2602 View commit details
    Browse the repository at this point in the history
  8. semexprs: workaround gensyms in dot expressions

    It's now possible that the field part of a dot expression is a
    identifier coming from a gensym. For example:
    
    ```nim
    template t(x: int) =
      type Typ {.gensym.} = float
      x.Typ
    ```
    
    So that field access still works in this case, `builtinFieldAccess` and
    `propertyWriteAccess` strip the identifier off of the gensym prefix
    first.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    d417b78 View commit details
    Browse the repository at this point in the history
  9. manual: remove mention of the template lookup bugs

    The `x.T` syntax now works when `T` is a gensym'ed symbos.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    a9988f0 View commit details
    Browse the repository at this point in the history
  10. tests: add tests

    The `knownIssue` test is for a bug that's pre-existing.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    2276e2b View commit details
    Browse the repository at this point in the history
  11. fix tcustom_numeric_literals test

    The field part of a dot expression may now be a symbol choice, which
    interferes with rendering of custom numeric literals (e.g., `1'lit`),
    where the special rendering was only enabled for `nkIdent` and `nkSym`
    nodes.
    
    To keep the test working, `getPIdent` (which is used by `isCustomLit`)
    now also returns the identifier for symbol-choice nodes.
    zerbina committed May 3, 2024
    Configuration menu
    Copy the full SHA
    137c8a7 View commit details
    Browse the repository at this point in the history

Commits on May 4, 2024

  1. Revert "fix tcustom_numeric_literals test"

    This reverts commit 137c8a7.
    zerbina committed May 4, 2024
    Configuration menu
    Copy the full SHA
    aa4d1f5 View commit details
    Browse the repository at this point in the history
  2. fix the tcustom_numeric_lit test properly

    Just retrieving the identifier from the symbol choice doesn't work,
    since then the symbol-choice node is passed to `gident`, where `atom`
    then crashes because symbol-choices are not allowed (a symbol-choice
    is, not necessarily, an atom, so this is correct).
    
    Instead of `getPIdent` retrieving an identifier from a symbol-choice,
    `isCustomLit` now special-cases symbol-choices.
    zerbina committed May 4, 2024
    Configuration menu
    Copy the full SHA
    66a51ee View commit details
    Browse the repository at this point in the history

Commits on May 5, 2024

  1. semtempl: merge nkDotExpr/nkAccQuoted handling

    This restores the previous behaviour of quoted identifiers with regards
    to symbol binding of (they ignore injected symbols, for whatever
    reason).
    zerbina committed May 5, 2024
    Configuration menu
    Copy the full SHA
    9a1cca9 View commit details
    Browse the repository at this point in the history