Skip to content

sema: Add missing type-checking logic on attributes with bodies - #2866

Open
xymus wants to merge 2 commits into
nitlang:masterfrom
xymus:attr-typing
Open

xymus wants to merge 2 commits into
nitlang:masterfrom
xymus:attr-typing

Conversation

@xymus

@xymus xymus commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Address two issues in the body block of an attribute: one miscompile and some missing diagnostics.

  1. Local variables with a static type defined within a loop need repeated visits until a fixed point is reached. We did that correctly for method bodies in Fix type adaptation when there is loops #1257 but attribute bodies were left out.

  2. The warnings on useless null tests, type tests and casts are reported by a visit after the typing. This was introduced for methods in Adaptive typing: fix buggy warning messages #1524 but attributes with a body never triggered it.

Both issues are addressed by sharing the logic visiting the body between methods and attributes, applying the correct method logic to attributes as well.

Local variables with a static type defined within a loop need repeated
visits until a fixed point is reached. We did that correctly for method
bodies in nitlang#1257 but attribute bodies were left out.

Let's apply the same logic for both method bodies and attributes. This
addresses miscompiles.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Test Results

    67 files     337 suites   15m 10s ⏱️
14 246 tests 13 699 ✅ 547 💤 0 ❌
14 642 runs  14 080 ✅ 562 💤 0 ❌

Results for commit bc40040.

♻️ This comment has been updated with latest results.

Add another missing type-checking step to attribute blocks. The warnings
on useless null tests, type tests and casts are reported by a visit
after the typing. This visit was introduced for method bodies in nitlang#1524
but attributes were left out, so these warnings were never reported in
attribute blocks or in the expressions of attribute initializers.

Let's gather the fixed point and this visit in `visit_body`,
shared by method and attribute bodies.

Remove the dead `do_typing` and its call site to the old `visit_body`.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
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.

1 participant