fix(bindings-csharp): allow [SpacetimeDB.Type] newtype structs as primary keys#5463
Open
ritankarsaha wants to merge 1 commit into
Open
Conversation
Author
|
@Shubham8287 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Fixes #5425
Allows
[SpacetimeDB.Type]structs that wrap exactly one SpacetimeDB-supported primary-key type to be used as[PrimaryKey],[Unique], or single-column index columns without theSTDB0003diagnostic.Example that now works:
How it works:
BSATN encodes a single-field product struct as pure field bytes with no framing — identical bytes to the underlying scalar. A newtype of ulong therefore serializes identically to a bare ulong. The fix teaches ColumnTypeValidation.IsEquatable() to recognize these newtype wrappers, using SpacetimeDbFieldDiscovery to inspect only the fields declared in
the [SpacetimeDB.Type]-annotated partial (the same set the BSATN codegen serializes). Multi-field structs and nullable wrappers continue to be rejected with STDB0003.
The change also updates the scheduled table PK check to accept a newtype of ulong in addition to a bare ulong.
API and ABI breaking changes
None. This is a purely additive change. All previously valid code in unaffected.
Expected complexity level and risk
2/5.
The diff is small and self-contained to Codegen/Module.cs. It reuses the existing SpacetimeDbFieldDiscovery helper (already used by BSATN.Codegen) to enumerate BSATN fields, keeping the detection logic consistent with what the serializer actually emits. The main risk area is the IsEquatable extension — any type that now passes this check but shouldn't would silently generate incorrect index code, but the two-guard check (struct + [SpacetimeDB.Type] + exactly one field + that field passes IsEquatable) is conservative.
Testing