feat: allow empty struct literals assigned to blank identifier (interface compliance check)#154
Open
jay-babu wants to merge 1 commit into
Open
feat: allow empty struct literals assigned to blank identifier (interface compliance check)#154jay-babu wants to merge 1 commit into
jay-babu wants to merge 1 commit into
Conversation
…face compliance check) (#1) * Allow empty structs assigned to blank identifier for interface compliance checks --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jay-babu <36803168+jay-babu@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds analyzer behavior to permit empty struct literals when used in the common Go interface-compliance idiom (var _ IFace = T{} / var _ IFace = &T{}), and introduces test coverage for that behavior.
Changes:
- Update empty-struct allowance logic to always permit assignments to the blank identifier in
vardeclarations. - Add new analysistest fixture package covering blank-identifier cases (allowed and disallowed contexts).
- Minor cleanup in testdata
go.mod(remove trailing blank line).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| analyzer/analyzer.go | Adds isAssignedToBlankIdentifier and uses it to allow empty literals in blank-identifier var declarations. |
| analyzer/analyzer_empty_test.go | Registers the new blank-identifier fixture package in the empty-allowance test suite. |
| analyzer/testdata/config/allow_empty/blank_identifier/blank_identifier.go | New test fixture exercising allowed var _ ... = T{} / &T{} and disallowed non-var _ uses. |
| analyzer/testdata/go.mod | Removes a trailing blank line. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+183
to
+191
| // Start from composite literal and go up the stack | ||
| for i := len(stack) - 1; i > 0; i-- { | ||
| parent := stack[i-1] | ||
|
|
||
| switch p := parent.(type) { | ||
| case *ast.ValueSpec: | ||
| // var _ = StructType{} or var _ Interface = StructType{} | ||
| return len(p.Names) > 0 && p.Names[0].Name == "_" | ||
|
|
| } | ||
|
|
||
| return false | ||
|
|
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.
No description provided.