Skip to content

Commit

Permalink
Mark external modules as forign
Browse files Browse the repository at this point in the history
Previously, the names of forign types in the top level were omitted,
since the top level module is always "".

Apply the same fix for enum types.
  • Loading branch information
iwahbe committed Nov 22, 2022
1 parent 6c046a9 commit 724fae5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions pkg/codegen/go/gen.go
Expand Up @@ -40,6 +40,11 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

// A signifier that the module is external, and will never match.
//
// This token is always an invalid module since ':' is not allowed within modules.
const ExternalModuleSig = ":always-external:"

type typeDetails struct {
// Note: if any of {ptr,array,map}Input are set, input and the corresponding output field must also be set. The
// mark* functions ensure that these invariants hold.
Expand Down Expand Up @@ -242,10 +247,7 @@ func (pkg *pkgContext) resolveEnumType(t *schema.EnumType) string {
}

extPkgCtx, _ := pkg.contextForExternalReference(t)
enumType := extPkgCtx.tokenToEnum(t.Token)
if !strings.Contains(enumType, ".") {
enumType = fmt.Sprintf("%s.%s", extPkgCtx.pkg.Name, enumType)
}
enumType := extPkgCtx.typeString(t)
return enumType
}

Expand Down Expand Up @@ -730,6 +732,7 @@ func (pkg *pkgContext) contextForExternalReference(t schema.Type) (*pkgContext,
extPkgCtx.pkgImportAliases = pkgImportAliases
extPkgCtx.externalPackages = pkg.externalPackages
mod := tokenToPackage(extPkg, goInfo.ModuleToPackage, token)
extPkgCtx.mod = ExternalModuleSig

return extPkgCtx, *maps[mod].detailsForType(t)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/codegen/go/gen_program_expressions.go
Expand Up @@ -168,8 +168,10 @@ func (g *generator) genSafeEnum(w io.Writer, to *model.EnumType) func(member *sc
}
memberTag, err := makeSafeEnumName(memberTag, enumName)
contract.AssertNoErrorf(err, "Enum is invalid")
namespace := tokenToModule(to.Token)
g.Fgenf(w, "%s.%s", namespace, memberTag)
pkg, mod, _, _ := pcl.DecomposeToken(to.Token, to.SyntaxNode().Range())
mod = g.getModOrAlias(pkg, mod, mod)

g.Fgenf(w, "%s.%s", mod, memberTag)
}
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/codegen/testing/test/program_driver.go
Expand Up @@ -113,8 +113,6 @@ var PulumiPulumiProgramTests = []ProgramTest{
{
Directory: "aws-webserver",
Description: "AWS Webserver",
SkipCompile: codegen.NewStringSet("go"),
// Blocked on go: TODO[pulumi/pulumi#8070]
},
{
Directory: "simple-range",
Expand Down
Expand Up @@ -25,9 +25,9 @@ func main() {
if err != nil {
return err
}
ami, err := aws.GetAmi(ctx, &GetAmiArgs{
Filters: []GetAmiFilter{
GetAmiFilter{
ami, err := aws.GetAmi(ctx, &aws.GetAmiArgs{
Filters: []aws.GetAmiFilter{
aws.GetAmiFilter{
Name: "name",
Values: []string{
"amzn-ami-hvm-*-x86_64-ebs",
Expand Down

0 comments on commit 724fae5

Please sign in to comment.