Skip to content

RM-37337: Do not report prefer-const-variables-over-non-const-global-variables on mutations#111

Merged
brouwers-tiobe merged 2 commits intomainfrom
37337-no-const-on-mutate-dict
Jan 23, 2026
Merged

RM-37337: Do not report prefer-const-variables-over-non-const-global-variables on mutations#111
brouwers-tiobe merged 2 commits intomainfrom
37337-no-const-on-mutate-dict

Conversation

@brouwers-tiobe
Copy link
Contributor

See RM-37337.

The const annotation should only be checked for a varibale declaration, not mutation. Going by https://docs.julialang.org/en/v1/manual/variables/#man-assignment-expressions, it gives examples of instances of mutation vs assignment:

That is, a[i] = value (an alias for setindex!) mutates an existing array object in memory, accessible via either a or b. Subsequently setting a = 3.14159 does not change this array, it simply binds a to a different object; the array is still accessible via b. Another common syntax to mutate an existing object is a.field = value (an alias for setproperty!), which can be used to change a mutable struct. There is also mutation via dot assignment, for example b .= 5:7 (which mutates our array b in-place to contain [5,6,7]), as part of Julia's vectorized "dot" syntax.

This PR excludes struct mutation and array mutation from prefer-const-variables-over-non-const-global-variables, meaning assignments such as A.x = 1 and A[i] = 2 now are no longer reported on.

…` on mutations

Field assignments `A.x = 1` and array element assignments `A[i] = 2` now
are no longer reported
Copy link
Contributor

@zon-tiobe zon-tiobe left a comment

Choose a reason for hiding this comment

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

One minor nitpick about annotations is all.

Looks to be good!

Copy link
Contributor

@zon-tiobe zon-tiobe left a comment

Choose a reason for hiding this comment

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

LGTM!

@brouwers-tiobe brouwers-tiobe merged commit 423d7be into main Jan 23, 2026
3 checks passed
@brouwers-tiobe brouwers-tiobe deleted the 37337-no-const-on-mutate-dict branch January 23, 2026 08:12
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.

2 participants