Repository navigation
Improve handling and error messages when using this inside an anonymous class - #1305
Conversation
WalkthroughAdds an anonymous-class early-return in generic-type pretty printing and threads VisitorState through GenericsChecks’ type-extraction and inference code, including special handling for Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant GC as GenericsChecks
participant GT as getTreeType(tree, state)
participant Sym as Symbol/ASTHelpers
participant PP as GenericTypePrettyPrintingVisitor
GC->>GT: resolve type for a tree (passes VisitorState)
alt tree is Identifier "this" inside anonymous class
GT->>Sym: derive enclosing anonymous class type via symbol.owner/enclosing
Sym-->>GT: annotated anonymous-class Type
else other tree kinds
GT->>Sym: fallback to ASTHelpers.getType(tree) or symbol.type
Sym-->>GT: Type (may include annotations)
end
GT-->>GC: return resolved Type (state-aware)
GC->>GC: generate constraints / infer generics (state threaded)
GC->>PP: request pretty-print of type for diagnostics
alt type.isAnonymous()
PP-->>GC: return t.toString() (early return)
else
PP-->>GC: return pretty-printed type
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60–90 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-08-28T04:54:20.953ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai configuration |
CodeRabbit configurationlanguage: en-US
tone_instructions: ''
early_access: false
enable_free_tier: true
reviews:
profile: chill
request_changes_workflow: false
high_level_summary: true
high_level_summary_placeholder: '@coderabbitai summary'
high_level_summary_in_walkthrough: false
auto_title_placeholder: '@coderabbitai'
auto_title_instructions: ''
review_status: true
commit_status: true
fail_commit_status: false
collapse_walkthrough: false
changed_files_summary: true
sequence_diagrams: true
estimate_code_review_effort: true
assess_linked_issues: true
related_issues: true
related_prs: true
suggested_labels: true
auto_apply_labels: false
suggested_reviewers: true
auto_assign_reviewers: false
in_progress_fortune: true
poem: false
labeling_instructions: []
path_filters: []
path_instructions: []
abort_on_close: true
disable_cache: false
auto_review:
enabled: true
auto_incremental_review: true
ignore_title_keywords: []
labels: []
drafts: false
base_branches: []
ignore_usernames: []
finishing_touches:
docstrings:
enabled: true
unit_tests:
enabled: true
pre_merge_checks:
docstrings:
mode: warning
threshold: 80
title:
mode: warning
requirements: ''
description:
mode: warning
issue_assessment:
mode: warning
custom_checks: []
tools:
ast-grep:
rule_dirs: []
util_dirs: []
essential_rules: true
packages: []
shellcheck:
enabled: true
ruff:
enabled: true
markdownlint:
enabled: true
github-checks:
enabled: true
timeout_ms: 90000
languagetool:
enabled: true
enabled_rules: []
disabled_rules: []
enabled_categories: []
disabled_categories: []
enabled_only: false
level: default
biome:
enabled: true
hadolint:
enabled: true
swiftlint:
enabled: true
phpstan:
enabled: true
level: default
phpmd:
enabled: true
phpcs:
enabled: true
golangci-lint:
enabled: true
yamllint:
enabled: true
gitleaks:
enabled: true
checkov:
enabled: true
detekt:
enabled: true
eslint:
enabled: true
flake8:
enabled: true
rubocop:
enabled: true
buf:
enabled: true
regal:
enabled: true
actionlint:
enabled: true
pmd:
enabled: true
cppcheck:
enabled: true
semgrep:
enabled: true
circleci:
enabled: true
clippy:
enabled: true
sqlfluff:
enabled: true
prismaLint:
enabled: true
pylint:
enabled: true
oxc:
enabled: true
shopifyThemeCheck:
enabled: true
luacheck:
enabled: true
brakeman:
enabled: true
dotenvLint:
enabled: true
htmlhint:
enabled: true
checkmake:
enabled: true
osvScanner:
enabled: true
chat:
art: true
auto_reply: true
integrations:
jira:
usage: auto
linear:
usage: auto
knowledge_base:
opt_out: false
web_search:
enabled: true
code_guidelines:
enabled: true
filePatterns: []
learnings:
scope: auto
issues:
scope: auto
jira:
usage: auto
project_keys: []
linear:
usage: auto
team_keys: []
pull_requests:
scope: auto
mcp:
usage: auto
disabled_servers: []
code_generation:
docstrings:
language: en-US
path_instructions: []
unit_tests:
path_instructions: []
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1305 +/- ##
============================================
- Coverage 88.49% 88.49% -0.01%
- Complexity 2476 2479 +3
============================================
Files 93 93
Lines 8214 8228 +14
Branches 1617 1623 +6
============================================
+ Hits 7269 7281 +12
Misses 474 474
- Partials 471 473 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…argument (uber#2037) Issue uber#1155 reported two false positives in JSpecify mode. A call on a `new` expression dropped the `@Nullable` type argument of the class, so `Inner<@nullable Object> mThing = new Inner<@nullable Object>().identity();` was reported as an assignment from `Inner<Object>`. Inside `new Callback<@nullable Integer>() { ... }`, `Callback<@nullable Integer> self = this;` was reported the same way. Both now pass: uber#1571 (0.13.6) fixed the call on a `new` expression, and uber#1305 (0.12.11) fixed `this` in an anonymous class. The test for the first case, `GenericsTests.callWithConstructorReceiver`, was still `@Ignore`d. The `@Ignore` is removed, and the test now also assigns the same call to `Inner<Object>`, which must be reported, so it fails whether the type argument is dropped or the call is no longer checked. `GenericsTests.thisUsageInAnonymousClass` passed `this` only as an argument; it now also assigns `this` to a local, in the anonymous class with a `@Nullable` type argument (no error) and in the one without it (error). Each case was seen failing with its fix disabled, under `:nullaway:test` on JDK 21: skipping the receiver substitution for a call on a `new` expression brings back the reported warning on `mThing`, and skipping the `this` branch of `getTreeType` brings it back on `self = this`. Fixes uber#1155 Assisted-by: Claude Code (claude-opus-5-5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Expanded coverage for generic nullability checks, including constructor receiver calls and assignments within anonymous-class callbacks. * Added checks for both accepted and incompatible assignments involving nullable callback types. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fixes #1202
We add correct handling for the case where the (generic) anonymous class has explicit type arguments, and a clearer error message for cases where the diamond operator is used (which we still don't handle fully). We had to pass in the
VisitorStateto thegetTreeTypefunction, necessitating a bunch of small changes.Summary by CodeRabbit
Bug Fixes
Tests