Skip to content

Variable name collisions in Go modules #6186

Closed

Description

@jedevc

Originally reported and summarized from https://discord.com/channels/707636530424053791/1178719192585879643/1178719192585879643 🎉

When generating dagger.gen.go, it's possible for the user to name their arguments to clash with other internal names.

For example, a user can name their arguments to collide with imported names, like json, fmt and os or with internal local variables like parent, inputArgs and err, or even with keywords, such as package.

These kind of collisions cause weird internal errors that don't really make much sense to the user - like Unmarshal undefined (type bool has no field or method Unmarshal).

We should update the Go modules SDK so that we can detect these cases, and rename local variables to avoid this kind of collision - e.g. if we have an argument named json, and we have json declared in an outer scope already, we should instead call the internal variable json2 (or similar, it doesn't hugely matter since it's in an internal function scope).

Activity

  1. changed the title [-]Zenith: variable name collisions in Go modules[/-] [+]Variable name collisions in Go modules[/+] on Mar 18, 2024
  2. added this to the next milestone on Oct 25, 2024
  3. locked and limited conversation to collaborators on Mar 24, 2026
  4. converted this issue into a discussion #12381 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions