Skip to content

Detect struct comparisons that bypass +noKrtEquals markers#4

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/investigate-linter-issue
Draft

Detect struct comparisons that bypass +noKrtEquals markers#4
Copilot wants to merge 6 commits intomainfrom
copilot/investigate-linter-issue

Conversation

Copy link

Copilot AI commented Jan 12, 2026

The linter missed cases where struct-typed fields are compared using == instead of delegating to .Equals(), allowing Go's default comparison to ignore +noKrtEquals markers on nested fields.

Problem

type listenerPolicy struct {
    proxyProtocol *int
    // +noKrtEquals reason: internal state
    http *HttpListenerPolicyIr
}

type ListenerPolicyIR struct {
    defaultPolicy listenerPolicy
}

// BUG: Compares ALL fields of listenerPolicy, including http
func (l ListenerPolicyIR) Equals(other ListenerPolicyIR) bool {
    return l.defaultPolicy == other.defaultPolicy  // Now flagged
}

When == compares structs, it compares every field regardless of markers. The linter previously only checked that fields are used, not how they're compared.

Changes

  • Added checkStructComparisons() to detect ==/!= on struct-typed fields
  • Traverses type info to identify struct types and check for marked fields
  • Reports diagnostic when comparison would bypass +noKrtEquals/+krtEqualsTodo markers
  • Suggests .Equals() delegation as the correct pattern

Test Coverage

  • Struct fields with +noKrtEquals markers compared via == (flagged)
  • Struct fields with +krtEqualsTodo markers compared via == (flagged)
  • Proper delegation using .Equals() (passes)
  • Both exported and unexported field scenarios
Original prompt

This section details on the original issue you should resolve

<issue_title>Investigate kgateway-dev/kgateway#13271 (comment)</issue_title>
<issue_description>Determine why the linter didn't catch a nested field within the listener policy IR struct:

type ListenerPolicyIR struct {
	ct            time.Time
	defaultPolicy listenerPolicy
	perPortPolicy map[uint32]listenerPolicy

	NoOrigin bool // +noKrtEquals reason: When set to true, suppress source reporting metadata from
	// ListenerPolicy specific fields that are irrelevant to the (now deprecated) HTTPListenerPolicy. Remove when HTTPListenerPolicy is removed.
}

type listenerPolicy struct {
	proxyProtocol                 *anypb.Any
	perConnectionBufferLimitBytes *uint32
	http                          *HttpListenerPolicyIr
}
```</issue_description>

<agent_instructions>Determine whether the code I inlined in the issue is a gap the linter doesn't handle correctly</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 12, 2026 18:52
Co-authored-by: timflannagan <9899409+timflannagan@users.noreply.github.com>
…rkers

Co-authored-by: timflannagan <9899409+timflannagan@users.noreply.github.com>
Co-authored-by: timflannagan <9899409+timflannagan@users.noreply.github.com>
Co-authored-by: timflannagan <9899409+timflannagan@users.noreply.github.com>
Co-authored-by: timflannagan <9899409+timflannagan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate linter issue in listener policy IR struct Detect struct comparisons that bypass +noKrtEquals markers Jan 12, 2026
Copilot AI requested a review from timflannagan January 12, 2026 19:04
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.

Investigate https://github.com/kgateway-dev/kgateway/pull/13271#issuecomment-3739843830

2 participants