Skip to content

encoding/protobuf: respect lexical scoping rules#4325

Open
SteveRuble wants to merge 1 commit into
cue-lang:masterfrom
SteveRuble:SteveRuble/fix-protobuf-relative-references
Open

encoding/protobuf: respect lexical scoping rules#4325
SteveRuble wants to merge 1 commit into
cue-lang:masterfrom
SteveRuble:SteveRuble/fix-protobuf-relative-references

Conversation

@SteveRuble
Copy link
Copy Markdown

This change modifies the protobuf converter to
respect lexical scoping when resolving relative
references. Previously, relative references were
resolved using the top-level scope, which meant
that references which were not fully-qualified
would fail to resolve. This change modifies the
logic so that it searches for the first element
of the reference name by iterating up the scope
chain until it finds a match.

This extends the existing .proto file used for
testing references to include a variety of
reference types, including relative,
fully-qualified, and ambiguous references.
It does NOT fix the existing bug where
non-fully-qualified references to shadowed
names end up always resolving to the shadowed
name in the generated CUE, because changing that
would require making the generated code opt in
to the experimental aliasv2 feature, which may
not be desirabled for all users.

This also fixes a bug in the proto generation
tests where the diff for golden files was
reversed, leading to confusing test failure
messages.

This work used LLM-powered tab completion,
but no other LLM tools.

Fixes #4323

@SteveRuble SteveRuble requested a review from cueckoo as a code owner April 6, 2026 14:46
@SteveRuble SteveRuble force-pushed the SteveRuble/fix-protobuf-relative-references branch 2 times, most recently from a5c350b to 526cb64 Compare April 6, 2026 17:15
This change modifies the protobuf converter to
respect lexical scoping when resolving relative
references. Previously, relative references were
resolved using the top-level scope, which meant
that references which were not fully-qualified
would fail to resolve. This change modifies the
logic so that it searches for the first element
of the reference name by iterating up the scope
chain until it finds a match.

This extends the existing .proto file used for
testing references to include a variety of
reference types, including relative,
fully-qualified, and ambiguous references.
It does NOT fix the existing bug where
non-fully-qualified references to shadowed
names end up always resolving to the shadowed
name in the generated CUE, because changing that
would require making the generated code opt in
to the experimental aliasv2 feature, which may
not be desirabled for all users.

This also fixes a bug in the proto generation
tests where the diff for golden files was
reversed, leading to confusing test failure
messages.

This work used LLM-powered tab completion.

Fixes cue-lang#4323

Signed-off-by: SteveRuble <SteveRuble@users.noreply.github.com>
@SteveRuble SteveRuble force-pushed the SteveRuble/fix-protobuf-relative-references branch from 526cb64 to 27dd3ac Compare April 6, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protobuf parser does not respect lexical scoping rules

1 participant