Skip to content

irverify: Naming.Aliases is held to no rule at all #317

Description

@OmarAlJarrah

Summary

Naming has four channels and irverify reads three of them. Source, Canonical and Hint
are read by checkNaming (namingChannels, ir/irverify/naming.go:90) — Hint for the presence
test only, which is #54. Aliases is read by nothing anywhere in the pipeline: it appears in
production code exactly once, at its own declaration.

$ grep -rn "Aliases" --include='*.go' ir/ pass/ compilers/ engine/ | grep -v _test.go
ir/naming.go:28:  // Aliases are alternate names for schema-resolution matching (Avro
ir/naming.go:31:  Aliases []string `json:"aliases,omitempty"`

(The compilers/openapi/internal/scan hit is a comment about YAML aliases, unrelated.)

Reproduction

A model whose aliases are cased, punctuated, empty and duplicated verifies clean and validates
clean:

m := &ir.Model{TypeCommon: ir.TypeCommon{
    ID:   "t/x/M",
    Name: ir.Naming{Source: "m", Canonical: "m",
        Aliases: []string{"UserID", "com.example.User", "", "dup", "dup"}},
}}
// irverify.Verify → no violation
// pass.Validate   → no diagnostic

Why it matters

An alias is an alternate name for schema-resolution matching (Avro aliases, Protobuf's
json_name alternates), so it is subject to the same invariant as the rest of the naming channel:
names are neutral, and an emitter owns casing and reserved-word escaping. An alias that arrives
already cased or already punctuated is a name the IR has decided the spelling of, which is exactly
what invariant 4 forbids and what ir/naming-cased and ir/naming-not-words exist to catch on
Canonical.

The empty and duplicated cases are cheaper claims and worth making at the same time: an empty
alias matches nothing and a repeated one matches twice, and both mean a compiler wrote a list it
did not mean to write.

Suggested shape

Extend checkNaming rather than adding a rule beside it — it already reaches every ir.Naming the
document holds through the shared walk, and namingChannels is where the fourth channel would be
read. The question worth settling first is which of the three existing content rules an alias is
held to. Canonical's grammar is the neutral lower_snake word sequence and an alias may
legitimately be a dotted fully-qualified name (com.example.User is what an Avro alias looks
like), so the answer is probably not "the same rules", and the issue should not be closed by
applying them unexamined.

Whatever set is chosen, ir/naming.go:28-31's doc comment should say it, since today it documents
what the field is for and nothing about what a well-formed entry looks like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions