diff --git a/go-runtime/compile/build.go b/go-runtime/compile/build.go index ebe1dbb055..bd00b987c8 100644 --- a/go-runtime/compile/build.go +++ b/go-runtime/compile/build.go @@ -1008,12 +1008,9 @@ func imports(m *schema.Module, aliasesMustBeExported bool) map[string]string { break } imports[path.Join("ftl", n.Module)] = "ftl" + n.Module - for _, tp := range n.TypeParameters { - if tpRef, ok := tp.(*schema.Ref); ok { - if tpRef.Module != "" && tpRef.Module != m.Name { - imports[path.Join("ftl", tpRef.Module)] = "ftl" + tpRef.Module - } + if tpRef, ok := tp.(*schema.Ref); ok && tpRef.Module != "" && tpRef.Module != m.Name { + imports[path.Join("ftl", tpRef.Module)] = "ftl" + tpRef.Module } } @@ -1067,10 +1064,16 @@ func addImports(existingImports map[string]string, newImportPathsAndDirs map[str for i := range len(pathComponents) { runes := []rune(pathComponents[len(pathComponents)-1-i]) for i, char := range runes { - if !unicode.IsLetter(char) && !(unicode.IsNumber(char) && i > 0) { + if !unicode.IsLetter(char) && !unicode.IsNumber(char) { runes[i] = '_' } } + if unicode.IsNumber(runes[0]) { + newRunes := make([]rune, len(runes)+1) + newRunes[0] = '_' + copy(newRunes[1:], runes) + runes = newRunes + } foldedComponent := string(runes) if i == 0 { currentAlias = foldedComponent diff --git a/go-runtime/compile/build_test.go b/go-runtime/compile/build_test.go index 68a3e92623..f824504cb8 100644 --- a/go-runtime/compile/build_test.go +++ b/go-runtime/compile/build_test.go @@ -67,8 +67,8 @@ func TestImportAliases(t *testing.T) { "github.com/some/pkg": "uniquedir", "github.com/example/path/to/pkg": "pkg_last", "github.com/last": "github_com_last", - "github.com/11/numeric": "_1_numeric", - "github.com/22/numeric": "_2_numeric", + "github.com/11/numeric": "_11_numeric", + "github.com/22/numeric": "_22_numeric", "github.com/same": "dir1", "github.com/two/aliaseswithonepkg": "aliaseswithonepkg", "ftl/moduleclash": "ftlmoduleclash",