Skip to content

analyzer: FieldError & BoundsError analysis#404

Merged
aviatesk merged 1 commit intomasterfrom
avi/field-bounds-error
Dec 18, 2025
Merged

analyzer: FieldError & BoundsError analysis#404
aviatesk merged 1 commit intomasterfrom
avi/field-bounds-error

Conversation

@aviatesk
Copy link
Owner

@aviatesk aviatesk commented Dec 16, 2025

Analyzer: FieldError & BoundsError analysis

Add static analysis for field access errors by hooking into
CC.builtin_tfunction to intercept getfield, setfield!,
fieldtype, and getglobal calls.

Two new report types are introduced:

  • FieldErrorReport (inference/field-error): reported when accessing
    a non-existent field by name
  • BoundsErrorReport (inference/bounds-error): reported when
    accessing a field by an out-of-bounds integer index

Note that the inference/bounds-error diagnostic is reported when code
attempts to access a struct field using an integer index that is out of
bounds, such as getfield(x, i) or tuple indexing tpl[i], and not
reported for arrays, since the compiler doesn't track array shape
information.

Reports from invalid setfield! and fieldtype, and general invalid
argument types are left as future TODO.

Also adjusts concrete evaluation logic to enable ad-hoc constant
propagation after failed concrete evaluation for better accuracy.

Closes #392
Also fixes #327

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 70.37037% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.65%. Comparing base (08be716) to head (8d048b6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/analysis/Analyzer.jl 70.00% 33 Missing ⚠️
src/diagnostics.jl 66.66% 5 Missing ⚠️
src/analysis/full-analysis.jl 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
- Coverage   64.68%   64.65%   -0.03%     
==========================================
  Files          44       44              
  Lines        5111     5212     +101     
==========================================
+ Hits         3306     3370      +64     
- Misses       1805     1842      +37     
Flag Coverage Δ
JETLS.jl 64.65% <70.37%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aviatesk aviatesk force-pushed the avi/field-bounds-error branch 2 times, most recently from 4777a56 to f42ab2e Compare December 18, 2025 09:58
@aviatesk aviatesk changed the title WIP: Analyzer: FieldError & BoundsError analysis Analyzer: FieldError & BoundsError analysis Dec 18, 2025
@aviatesk aviatesk changed the title Analyzer: FieldError & BoundsError analysis Analyzer: FieldError & BoundsError analysis Dec 18, 2025
@aviatesk aviatesk force-pushed the avi/field-bounds-error branch from f42ab2e to 458e23c Compare December 18, 2025 11:04
Add static analysis for field access errors by hooking into
`CC.builtin_tfunction` to intercept `getfield`, `setfield!`,
`fieldtype`, and `getglobal` calls.

Two new report types are introduced:
- `FieldErrorReport` (`inference/field-error`): reported when accessing
  a non-existent field by name
- `BoundsErrorReport` (`inference/bounds-error`): reported when
  accessing a field by an out-of-bounds integer index

Note that the `inference/bounds-error` diagnostic is reported when code
attempts to access a struct field using an integer index that is out of
bounds, such as `getfield(x, i)` or tuple indexing `tpl[i]`, and not
reported for arrays, since the compiler doesn't track array shape
information.

Reports from invalid `setfield!` and `fieldtype`, and general invalid
argument types are left as future TODO.

Also adjusts concrete evaluation logic to enable ad-hoc constant
propagation after failed concrete evaluation for better accuracy.
@aviatesk aviatesk force-pushed the avi/field-bounds-error branch from 458e23c to 8d048b6 Compare December 18, 2025 11:12
@aviatesk aviatesk merged commit 493e8bc into master Dec 18, 2025
19 of 22 checks passed
@aviatesk aviatesk deleted the avi/field-bounds-error branch December 18, 2025 11:53
@aviatesk aviatesk changed the title Analyzer: FieldError & BoundsError analysis analyzer: FieldError & BoundsError analysis Dec 18, 2025
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.

Diagnostics can end up "masked" due to bad property access / other errors ERROR: KeyError: key

1 participant