Skip to content

Commit a46d57b

Browse files
fix(generator): qualify method receivers that collide with arm/storage import aliases (#5504)
* fix(generator): qualify method receivers that collide with arm/storage import aliases A type whose name's last word is 'Storage' (e.g. FunctionsDeployment_Storage) yielded a method receiver 'storage', shadowing the storage conversion-package import alias in generated AssignProperties_To_* methods and breaking the build. CreateReceiver already qualifies reserved words and short (<=3 char) names; also qualify names that collide with the fixed conversion-package aliases (arm/storage). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Regenerate cognitiveservices UserOwnedStorage receivers The generator fix qualifies method receivers that collide with the arm/storage conversion-package import aliases. UserOwnedStorage's last word is "Storage", so its receiver changes from "storage" to "ownedStorage". Regenerated repo-wide; this is the only existing type affected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Andrei Dorin Oprea <noreply@anthropic.com>
1 parent 34f43dd commit a46d57b

3 files changed

Lines changed: 44 additions & 34 deletions

File tree

v2/api/cognitiveservices/v1api20250601/account_types_gen.go

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/tools/generator/internal/astmodel/identifier_factory.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,13 @@ func (factory *identifierFactory) CreateReceiver(name string) string {
232232

233233
base := words[len(words)-1]
234234

235-
// Prefix with a qualifying term if one is available,
236-
// AND either base is a reserved word, or it is too short (3 characters or less)
235+
// Prefix with a qualifying term if one is available, AND the base is a reserved word, is too
236+
// short (3 characters or less), or collides with a conversion-package alias (arm/storage) that
237+
// the generated code imports - a bare receiver named after one of those would shadow the package.
237238
if len(words) > 1 {
238-
if _, found := factory.reservedWords[strings.ToLower(base)]; found || len(base) <= 3 {
239+
lowerBase := strings.ToLower(base)
240+
_, reserved := factory.reservedWords[lowerBase]
241+
if reserved || len(base) <= 3 || forbiddenReceiverNames.Contains(lowerBase) {
239242
base = words[len(words)-2] + base
240243
}
241244
}
@@ -296,6 +299,10 @@ func createForbiddenReceiverSuffixes() set.Set[string] {
296299
return set.Make(status, spec)
297300
}
298301

302+
// forbiddenReceiverNames are lowercase receiver names that would shadow a conversion-package import
303+
// (e.g. a type ending in "Storage" yields receiver "storage", clashing with the storage subpackage alias).
304+
var forbiddenReceiverNames = set.Make(strings.ToLower(ARMPackageName), strings.ToLower(StoragePackageName))
305+
299306
func (factory *identifierFactory) CreateGroupName(group string) string {
300307
return strings.TrimPrefix(strings.ToLower(group), "microsoft.")
301308
}

v2/tools/generator/internal/astmodel/identifier_factory_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ func Test_CreateReceiver_GivenTypeName_ReturnsExpectedResult(t *testing.T) {
224224
{"DiskSku" + StatusSuffix, "diskSku"},
225225
// Conflicts with reserved words need more detail
226226
{"BlobRestoreRange" + StatusSuffix, "restoreRange"},
227+
// Conflicts with conversion-package import aliases (arm/storage) need more detail
228+
{"FunctionsDeployment_Storage", "deploymentStorage"},
229+
{"FunctionsDeployment_Storage" + StatusSuffix, "deploymentStorage"},
227230
}
228231

229232
factory := NewIdentifierFactory()

0 commit comments

Comments
 (0)