Skip to content

Fix @warning not applying to warnings from translation - #9495

Closed
cknitt wants to merge 2 commits into
fix-malformed-warning-repeatfrom
warning-attributes-in-translation
Closed

cknitt wants to merge 2 commits into
fix-malformed-warning-repeatfrom
warning-attributes-in-translation

Conversation

@cknitt

@cknitt cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member

Stacked on #9491.

Translation to Lambda reports some warnings itself, such as 102 for a polymorphic comparison. It applies the warning attributes of the nodes it translates again, but only on let bindings, expressions and module expressions. It skipped the others:

@warning("-102")
module M = {
  let compares = [1] == [2] // warning 102 anyway
}

The same happened for module rec, include, a type constraint such as @warning("-102") (e: bool), and floating @@warning items. In a build, @@warning("+102") at the top of a file never enabled 102. A one-step bsc compile only got it through the frontend's leftover warning state, which #9491 removes.

The fix. Translmod applies a floating attribute in a scope around the rest of its structure. It translates the rest of a structure before the item itself, so the scope ends before the items above the attribute are translated. Module bindings, recursive modules and includes get a scope of their attributes. transl_exp also applies the attributes of type constraints. A new Typedtree.exp_warning_attributes collects them, and typemod uses it for warning 113 too.

Tests. warning_102_attribute_scopes has one comparison in each of these scopes, plus a floating @@warning above and inside a module. Without the fix, all eight comparisons are reported; with it, only the two that no attribute silences.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du

cknitt and others added 2 commits December 1, 2026 19:41
Why:
    Builtin_attributes.warning_attribute both applied a warning setting
    and reported problems with it. The type checker enters a binding's
    warning scope several times, so a malformed payload was reported up
    to six times. The ~ppwarning:false flag of the repeated scopes only
    skipped @ppwarning. The frontend also applied and reported the
    leading @@warning items, and its warning state stayed in place for
    the type checker.

Builtin_attributes now has two kinds of scope. warning_scope applies and
reports, and only the type checker's first pass over a node uses it.
replay_warning_scope applies silently, for the type checker's repeated
passes, translation and Inline_not_stored. The ~ppwarning flag is gone.

The frontend runs the built-in PPX in a replay_warning_scope over the
leading floating attributes, so the warning state is restored before
type checking. The type checker then applies and reports these items in
order, as it already does when a build compiles the parsed .ast file.

Diagnostic modified (malformed @warning payload):
Example:
    @warning(3) let x = 1
Before (diagnostic):
    Warning number 47 (reported 6 times)
    illegal payload for attribute @warning.
    A single string literal is expected
After (diagnostic):
    Warning number 47 (reported once)
    illegal payload for attribute @warning.
    A single string literal is expected

Fixes #9488

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    Translation to Lambda reports some warnings itself, such as 102 for
    a polymorphic comparison. It applies the warning attributes of the
    nodes it translates again, but only on let bindings, expressions and
    module expressions. It skipped floating @@warning items and the
    attributes of module bindings, recursive modules, includes and type
    constraints. So `@warning("-102")` on a module did not silence 102
    inside it, and in a build `@@warning("+102")` never enabled it.

Translmod now applies a floating attribute in a scope around the rest of
its structure. It translates the rest of a structure before the item
itself, so the scope ends before the items above the attribute are
translated. Module bindings, recursive modules and includes get a scope
of their attributes. Translcore.transl_exp also applies the attributes of
type constraints, which a new Typedtree.exp_warning_attributes collects
in scope order, as typemod already did for warning 113.

Diagnostic modified (warning 102 in a module with @warning("-102")):
Example:
    @warning("-102")
    module M = {
      let compares = [1] == [2]
    }
Before (diagnostic):
    Warning number 102
    Polymorphic comparison introduced (maybe unsafe)
After (diagnostic): (nothing reported)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt added this pull request to stack #9496 December 1, 2026 19:44
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Apply @warning and @@warning to warnings reported during translation, such as warning 102, wherever they apply during type checking.

Semantic Diff

1 commit · Full page

Fix @warning not applying to warnings from translation

96f03a3 · cknitt + Claude · Dec 01, 2026, 19:43 UTC

Why

Translation to Lambda reports some warnings itself, such as 102 for a polymorphic comparison. It applies the warning attributes of the nodes it translates again, but only on let bindings, expressions and module expressions. It skipped floating @@warning items and the attributes of module bindings, recursive modules, includes and type constraints. So @warning("-102") on a module did not silence 102 inside it, and in a build @@warning("+102") never enabled it.

Translmod now applies a floating attribute in a scope around the rest of its structure. It translates the rest of a structure before the item itself, so the scope ends before the items above the attribute are translated. Module bindings, recursive modules and includes get a scope of their attributes. Translcore.transl_exp also applies the attributes of type constraints, which a new Typedtree.exp_warning_attributes collects in scope order, as typemod already did for warning 113.

Diagnostic modified (warning 102 in a module with @warning("-102"))

@warning("-102")
module M = {
  let compares = [1] == [2]
}

diagnostic

-Warning number 102
-Polymorphic comparison introduced (maybe unsafe)
+(nothing reported)

@cknitt cknitt added changelog:skip No release notes needed and removed changelog:skip No release notes needed labels Dec 1, 2026
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T19:47:30.619346Z 96f03a3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cknitt
cknitt removed this pull request from stack #9496 December 1, 2026 19:46
@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from 64174bf to dbe39ca Compare December 1, 2026 19:47
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Folded into #9491, which now fixes the warning attribute handling in one change.

@cknitt cknitt closed this Dec 1, 2026
@cknitt
cknitt deleted the warning-attributes-in-translation branch December 1, 2026 19:47
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 96f03a347a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 655,137,777 → 655,157,726 (±0.00%).

Generated projects: 627,310,985 → 627,348,013 (+0.01%).

Benchmark Base Head Change
packages/@rescript/belt/src/Belt.res 188,531 189,012 +0.26%
build/Namespace/edit 7,906,442 7,920,440 +0.18%

Instructions

In total: 9,128,180,350 → 9,130,092,818 (+0.02%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,223,840 21,258,892 +0.17%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,057,839 24,093,314 +0.15%
packages/@rescript/runtime/Stdlib_List.resi 24,415,969 24,451,201 +0.14%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,497,073 25,532,868 +0.14%
parse/RedBlackTree.res 14,916,076 14,935,393 +0.13%
parse/RedBlackTreeNoComments.res 14,505,287 14,523,866 +0.13%
packages/@rescript/runtime/Stdlib_String.resi 29,365,497 29,400,284 +0.12%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,189,574 31,223,658 +0.11%
packages/@rescript/belt/src/Belt_Array.resi 33,560,858 33,596,036 +0.10%
packages/@rescript/runtime/Stdlib_Date.resi 34,163,582 34,198,413 +0.10%

Output size

In total: 27,368,588 → 27,369,036 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request 96f03a3 compared with base 64174bf in this run.

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