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

Annotations generate a name collision - fixed #539

Merged
merged 1 commit into from
Aug 7, 2023

Commits on Aug 7, 2023

  1. Annotations generate a name collision - fixed

    This is a partial fix of capnproto#46
    
    > zombiezen commented on Aug 22, 2016:
    >
    > One of the notable examples is in persistent.capnp that the annotation and
    > the type collide.
    
    Also see capnproto/capnproto#323
    
    This commit changes the generated code for all annotations that start with
    a lowercase letter. Since the generated code in Go must start with an
    uppercase letter to be valid Go, this change appends an "_" to the name,
    regardless of whether there is a name collision already. (The thinking is
    that a name collision can happen in the future, and the renaming must be
    strictly an injective function, meaning that Go identifiers are always
    chosen the same regardless of other names. This way the codegen will not
    cause painful refactors in other code due to a name change later.)
    
    The capnp files in this repo under `std` all have $Go.name() annotations
    due to this bug. This removes one of them (std/capnp/persistent.capnp) and
    replaces it with a unit test that compiles the generated code. Actually
    doing a "go build" is one step father than previous unit tests.
    
    The thinking is to not add too many calls to "go build," since there is a lot
    of overhead and slow unit tests are discouraging. This commit appears to add
    about 250ms to the time it takes to run a "go test" in the capnpc-go subdir.
    
    This also tweaks templates/interfaceClient to fix a problem if an interface is
    empty. The {{range .Methods -}} block in interfaceClient has a side effect of
    marking the "context" package for import, and an empty interface skips that.
    Since Resolve() also depends on the "context" package, this adds a call to
    {{$.G.Imports.Context}}.Context to ensure it also marks "context" as used.
    davidhubbard committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    0a83a6d View commit details
    Browse the repository at this point in the history