Skip to content

feat: allow empty struct literals assigned to blank identifier (interface compliance check)#154

Open
jay-babu wants to merge 1 commit into
GaijinEntertainment:masterfrom
jay-babu:master
Open

feat: allow empty struct literals assigned to blank identifier (interface compliance check)#154
jay-babu wants to merge 1 commit into
GaijinEntertainment:masterfrom
jay-babu:master

Conversation

@jay-babu

Copy link
Copy Markdown

No description provided.

…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>
Copilot AI review requested due to automatic review settings March 13, 2026 16:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 var declarations.
  • 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 thread analyzer/analyzer.go
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 == "_"

Comment thread analyzer/analyzer.go
}

return false

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