Just a minor issue - when you declare an argument in some method named json, it collides with the import "encoding/json" in the generated code (dagger.gen.go).
Context: I am creating a dagger module for Anchore Grype and I want to control, whether the output format should be in JSON or not. So I just defined an Optional[bool] argument named json. I sync'd the module and some errors showed up - Unmarshal undefined (type bool has no field or method Unmarshal). The import got shadowed by the variable.
Could be fixed by importing the json module under an alias - maybe _json?
#Zenith: json collision
1 messages · Page 1 of 1 (latest)
Could be fixed by importing the json module under an alias - maybe
_json?
agh there's gonna be loads of these sadly (fmt and os), not all of them imports 😦 e.g. parent, inputArgs, err.
Not quite sure what the best way to resolve this is going to be. I think during codegen we'll need to keep track of what names have already been introduced in the current scope, and then ensure that we don't use them again.
@surreal ridge we've talked about general principles for these collisions. In Python, I know that the post underscore is prefrerred (e.g. from_). I'll create an issue to track and produce docs.
is it necessary for the codegen to live in the same main package? that'd solve all those issues
I know it's convenient so users don't have to append the package name when specifying types, but maybe adding a meaningful and short package is not that bad
it's not just the package stuff, there's also the question of how it overlaps with local variables we need to create (go needs several 😢)
I don't know what the correct solution is. Also I don't know what other collisions could happen. As I said I just wanted a json arg to work. I don't think that we need to worry about every overlapping variable/import, since some arguments have a much smaller chance of being used. Maybe just prepend/append the imports with an underscore or something.
I honestly like having the generated code in the same package, but wouldn't mind it being in some other package.