Skip to content

Fix issue #277: proper rich check effect support for function variables#401

Open
nickita-khylkouski wants to merge 4 commits intouber-go:mainfrom
nickita-khylkouski:fix/issue-277
Open

Fix issue #277: proper rich check effect support for function variables#401
nickita-khylkouski wants to merge 4 commits intouber-go:mainfrom
nickita-khylkouski:fix/issue-277

Conversation

@nickita-khylkouski
Copy link
Contributor

Summary

This PR fixes the false positive where function variables (e.g., s.f() where f is a function field) were incorrectly flagged as nil when the error was properly checked.

Before: v, err := s.f(); if err != nil { return }; _ = *v → false positive warning
After: No warning (error is checked)

Changes

  • Add FuncVarRetAnnotationKey: New annotation key type for function variable returns that doesn't require a *types.Func declaration
  • Add getFuncVarReturnProducers helper: Generates proper FuncReturn producers with NeedsGuard and IsFromRichCheckEffectFunc flags for rich check effect integration
  • Update FuncReturn.Prestring: Handle the new FuncVarRetAnnotationKey type
  • Update primitivizer.site: Handle keys with nil Object() for local-only annotations
  • Add test cases: Cover both false positive (error checked) and true positive (error ignored) scenarios

Test plan

  • All existing tests pass
  • New test file issue277_function_pointer.go covers:
    • Function pointer field calls with error check (no warning)
    • Function pointer field calls without error check (warning expected)
    • Local function variables with/without error check
    • Parameter function variables with/without error check

Fixes #277

🤖 Generated with Claude Code

nickita-khylkouski and others added 4 commits January 27, 2026 22:03
… effect processing

For issue uber-go#277, function pointers with error-returning or ok-returning
signatures should trigger rich check effects, but the existing code
suppressed all function variable calls as TrustedFuncNonnil.

This change checks the function signature and only applies the
non-nil workaround for non-error/non-ok-returning function variables,
allowing error/ok-returning function variables to generate proper
rich check effects.

Fixes uber-go#277
…ction variables

This commit partially fixes the false positives for function variables with
error/ok return signatures by distinguishing them from other function variables.

Changes:
- Modified parse_expr_producer.go to check if function variables are
  error-returning or ok-returning using typeshelper.GetFuncSignature
- For error/ok-returning function variables, generate simple producers
  using TrustedFuncNilable/TrustedFuncNonnil
- For other function variables, keep the TrustedFuncNonnil{:never} workaround

Limitations:
- Rich check effects are not properly implemented for function variables yet
- True negatives (unchecked error/ok returns) are still not detected
- This is a temporary workaround until proper function variable support is added

This fixes some false positives but doesn't fully resolve issue uber-go#277.

TODO: Implement proper rich check effect support for function variables so that
      checked cases (if err != nil) don't warn and unchecked cases do warn.
…turning function variables

- Modified parse_expr_producer.go to distinguish between error/ok-returning and other function variables
- For non-error/ok function variables: continue using TrustedFuncNonnil to suppress false positives
- For error/ok function variables: generate specialized producers (TrustedFuncNilable/Tautology) to enable tracking
- Updated both *ast.Ident and *ast.SelectorExpr cases to handle f() and s.f() patterns
- Added comprehensive TODO comments explaining limitation: proper FuncReturn producers require creating synthetic *types.Func or modifying annotation key system
- Test status: basic producer generation works, but requires further work for full integration with rich check effects
…variables

This commit fixes the false positive where function variables (e.g., s.f()
where f is a function field) were incorrectly flagged as nil when the
error was properly checked.

Changes:
- Add FuncVarRetAnnotationKey: new annotation key type for function variable
  returns that doesn't require a *types.Func declaration
- Add getFuncVarReturnProducers helper: generates proper FuncReturn producers
  with NeedsGuard and IsFromRichCheckEffectFunc flags
- Update FuncReturn.Prestring: handle FuncVarRetAnnotationKey
- Update primitivizer.site: handle keys with nil Object()

The fix ensures:
1. When error is checked (if err != nil { return }), no warning is reported
2. When error is ignored (v, _ := f()), a warning is correctly reported

Fixes uber-go#277

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Add support for rich effect functions via function pointers

1 participant