Skip to content

query: a message-typed field of a reference is taken as its pointer, and compared by value - #2

Merged
lesomnus merged 1 commit into
mainfrom
message-field-in-ref
Oct 10, 2026
Merged

lesomnus merged 1 commit into
mainfrom
message-field-in-ref

Conversation

@lesomnus

Copy link
Copy Markdown
Member

Fixes #1.

A unique index with a timestamp among its fields generated two defects in query.g.go:

  • The constructor did not compile. ShiftBySlot(desk string, starts_at timestamppb.Timestamp) took the timestamp by value. useGoType with the decayed type names a message without its pointer, and only an edge was given one (*…Ref). A new argType gives the type the reference's setter takes. It is used by all four constructors (By<Field>, GetBy<Field>, By<Index>, GetBy<Index>), so a unique message-typed field is covered as well.
  • Picks compared pointers. (x.GetStartsAt() == v.GetStartsAt()) compiles, and asks whether the two are one message. A reference built anywhere other than from the row's own field never picked the row. A message-typed field is now compared with proto.Equal, in the single-field case and in the index case.

Tests

internal/apptest gains Shift, unique over (desk, starts_at), and TestRefByAnIndexWithATimestamp. A reference picks its row from a fresh Timestamp of the same instant, does not pick another desk or another time, and a row with no identifier is named by its index.

On the old generator the package does not build (cannot use v2 (variable of type *timestamppb.Timestamp) as timestamppb.Timestamp value in argument to ShiftBySlot). Locally buf generate (twice), gofmt, build, vet and go test ./... pass.

Found while fixing protobuf-orm/protoc-gen-orm-ent#2, whose test needs this to compile.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk

…and compared by value

A unique index with a timestamp among its fields generated a constructor
that took the timestamp by value -- `ShiftBySlot(desk string, starts_at
timestamppb.Timestamp)` -- and so did not compile: `useGoType` with the
decayed type names a message without its pointer, and only an edge was
given one. The constructors now take what the reference's setter takes,
written once in argType, for a unique field as well as an index.

And `Picks` compared the two timestamps with `==`, which compiles and asks
whether they are one message: a reference built anywhere but from the
row's own field never picked the row. A message-typed field is compared
with proto.Equal.

internal/apptest has a Shift, unique over (desk, starts_at), and a test
of both; the old generator does not build it.

Fixes #1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk
@lesomnus
lesomnus merged commit f9ac5b6 into main Oct 10, 2026
1 check passed
@lesomnus
lesomnus deleted the message-field-in-ref branch October 10, 2026 06:55
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.

A unique index with a timestamp among its fields generates a constructor that does not compile, and a Picks that compares pointers

1 participant