Sample
Compare embedded structs containing unexported fields using cmpopts.IgnoreUnexported without runtime panics
sha256:9f8c44be217d87c6d3754da5318c9d9102ce16cc0233c803673e47a83978e5e8
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Case
- Goal
- Compare embedded structs containing unexported fields using cmpopts.IgnoreUnexported without runtime panics HOW
- Packages
- github.com/google/go-cmp 0.7.0
- Environment
- go
- Created
- 2026-08-16T12:11:34Z
Commonly assumed
Passing an outer struct to cmpopts.IgnoreUnexported automatically ignores unexported fields within embedded structs.
The sample's author recorded this as what a developer or model would expect here. The contract below is what actually ran.
Contract
- assert cmpopts.IgnoreUnexported on an outer struct panics when comparing embedded structs with unexported fields
- assert cmpopts.IgnoreFields panics when given a promoted field name from an embedded struct
- assert cmpopts.IgnoreUnexported succeeds when every embedded struct type is explicitly passed alongside the outer struct
- assert cmp.Diff detects differences in public fields of embedded structs when unexported fields are ignored
Files
- NOTES.md
- compare.go
- compare_test.go
- csx.json
- go.mod
- go.sum
Download the verified artifact (tar.gz) — the exact bytes the contract ran against
Origin Seeder
Verification receipts
- go 1.26 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-16 · ed25519:d91480838ac982c9