Skip to content

Warn when a [Constraints] rule reads a static field declared below it - #101

Open
Mpdreamz wants to merge 1 commit into
mainfrom
heed/browse/issue-48-f08c45
Open

Mpdreamz wants to merge 1 commit into
mainfrom
heed/browse/issue-48-f08c45

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Closes #48

C# initialises static fields in declaration order, so a rule whose initializer reads a field declared below it is built with default. The generator now reports NECG030 (warning) at the read.

Reads inside a lambda or local function are not reported: they happen when the delegate runs, after every static is set. That means the literal example in the issue (o => o.Confirm(Clerk)) is fine at runtime; the hazard is a direct read such as Make(Clerk).

Same-file declarations only; partial-file order is not defined. No code fix, the message says to move the field up. README documents the id.

Tests (FieldOrderTests): reported when below, not when above, not inside a lambda. Mutating the order comparison fails two of them.

🤖 Generated with Claude Code

… (NECG030)

C# initialises static fields in declaration order, so a rule built from a
later field gets default. Reads inside lambdas are skipped: they happen when
the lambda runs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A defect fixed (patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static field order in a [Constraints] class can hand a rule a null

1 participant