Skip to content

fix: unrelated struct with that shape can be misclassified#39

Merged
asadijabar merged 1 commit into
mainfrom
fix/unrelated-struct-with-that-shape-can-be-misclassified
Feb 13, 2026
Merged

fix: unrelated struct with that shape can be misclassified#39
asadijabar merged 1 commit into
mainfrom
fix/unrelated-struct-with-that-shape-can-be-misclassified

Conversation

@Azhovan
Copy link
Copy Markdown
Owner

@Azhovan Azhovan commented Feb 13, 2026

What

  • Tighten optional detection in binding.go so only rigging.Optional[T] is treated as optional.
  • Add regression coverage in binding_bind_test.go to ensure lookalike structs (Value + Set bool) are handled as normal nested structs.

Why

Structural detection could misclassify unrelated structs, causing nested fields to be skipped during binding. This fix prevents silent misbinding and keeps optional semantics scoped to the intended type.

Type

  • Fix
  • Feature
  • Docs
  • Performance
  • Breaking change

Testing

Verified with formatting, targeted regression checks, full test suite, vet, and coverage:

gofmt -w binding.go binding_bind_test.go
go test ./... -run 'TestBindStruct_ValueSetLookalikeStructIsNotOptional|TestBindStruct_OptionalField|TestBinding_ConvertValue_Optional'
go test ./...
go vet ./...
go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out | tail -n 1

@Azhovan Azhovan self-assigned this Feb 13, 2026
@Azhovan Azhovan requested a review from asadijabar February 13, 2026 20:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where user-defined structs with Value and Set bool fields could be incorrectly identified as rigging.Optional[T] types, causing nested fields to be skipped during binding. The fix adds package path and type name checks to the isOptionalType function, ensuring only actual rigging.Optional[T] types are treated as optional.

Changes:

  • Enhanced isOptionalType() with package path and type name prefix validation to prevent misclassification
  • Added regression test to verify lookalike structs are properly handled as nested structs

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
binding.go Added optionalTypePkgPath variable and strengthened isOptionalType() with package path and name checks
binding_bind_test.go Added TestBindStruct_ValueSetLookalikeStructIsNotOptional to verify lookalike structs bind correctly as nested types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asadijabar asadijabar merged commit a6faf49 into main Feb 13, 2026
11 checks passed
@github-actions github-actions Bot deleted the fix/unrelated-struct-with-that-shape-can-be-misclassified branch February 13, 2026 20:25
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.

3 participants