Skip to content

Fix @warning reported several times and ignored in translation - #9491

Merged
cknitt merged 1 commit into
fix-printer-constraint-attributesfrom
fix-malformed-warning-repeat
Dec 2, 2026
Merged

cknitt merged 1 commit into
fix-printer-constraint-attributesfrom
fix-malformed-warning-repeat

Conversation

@cknitt

@cknitt cknitt commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #9488. Stacked on #9498, a formatter fix that the new test fixture needs.

A malformed @warning or @warnerror payload was reported up to six times, and some warning attributes had no effect on warnings reported during translation:

@warning(3) let x = 1 // warning 47, six times

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

The cause. Builtin_attributes.warning_attribute both applied a warning setting and reported problems with it. Several phases apply the same attributes:

  • The type checker enters a binding's warning scope once for each of its passes. The ~ppwarning:false flag of the repeated passes only skipped @ppwarning, so a malformed payload was reported on every pass.
  • The frontend applied and reported the leading @@warning items for the built-in PPX, and left its warning state in place for the later phases.
  • Translation, which reports warnings such as 102, applied the attributes of let bindings, expressions and module expressions again, but not those of module bindings, module rec, include, type constraints, expression statements and floating @@warning items. In a build, @@warning("+102") therefore never enabled 102.

The fix.

  • One reporter. Builtin_attributes 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 (including the second pass over a module rec), the frontend, translation and Inline_not_stored. The ~ppwarning flag is gone.
  • Clean phase boundary. The frontend runs the built-in PPX in a replay_warning_scope over the leading floating attributes. So type checking starts from the command line's warning state, in one-step compiles as in builds.
  • Complete replay in translation. 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, module rec, include and expression statements get a scope of their attributes, and transl_exp applies the attributes of type constraints. The scope of a let or module binding also covers the checks of its @inline attribute (warnings 47, 53 and 54). A new Typedtree.exp_warning_attributes collects those; typemod already needed them for warning 113.

Behaviour changes to review. In builds, a leading @@warning("+102") now enables warning 102, which can newly fail a build that also makes 102 an error. And @warning("-102") now silences 102 on modules, include and type constraints.

Known gaps (both on master already):

  • An operand of an arithmetic operator is type checked twice, so a malformed @warning on it is still reported twice. Filed as Operands of arithmetic operators are type checked twice #9500.
  • Attributes on a locally abstract type, (@warning("-102") type a, x) => …, don't reach translation, because the typed tree doesn't keep them.

Tests.

  • warning_47_warning_payload_once: a malformed payload on @@warning, a let, an expression, a module and a module rec, a malformed @warnerror list, and a @@ppwarning, each now reported once.
  • warning_47_warning_payload_order: a later @@warning("-47") doesn't hide an earlier malformed item.
  • warning_102_attribute_scopes: one comparison in each scope above, nested constraints where the innermost attribute wins, and floating @@warning items above and inside a module.
  • warning_53_inline_attribute_scope: @warning("-53") covers @inline on a let and on a module.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Report a malformed @warning or @warnerror payload and @@ppwarning only once.
  • Apply @warning and @@warning to warnings reported during translation, such as warning 102, also on modules, includes, type constraints, expression statements and floating @@warning items.

Semantic Diff

1 commit · Full page

✏️ Fix @warning reported several times and ignored in translation

d9aebad · cknitt + Claude · Dec 01, 2026, 19:46 UTC · edited

Why

Builtin_attributes.warning_attribute both applied a warning setting and reported problems with it. The type checker enters a binding's warning scope once for each of its passes, 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 left its warning state in place for the type checker and translation.

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

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, including the second pass over a recursive module, the frontend, 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 type checking starts from the command line's warning state, in one-step compiles as in builds.

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, includes and expression statements get a scope of their attributes, and the scope of a binding also covers the checks of its @inline attribute. 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 (malformed @warning payload)

@warning(3) let x = 1

diagnostic

-Warning number 47 (reported 6 times)
+Warning number 47 (reported once)
 illegal payload for attribute @warning.
 A single string literal is expected

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)

Fixes #9488

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.51%. Comparing base (738c317) to head (d9aebad).

Additional details and impacted files
@@                          Coverage Diff                          @@
##           fix-printer-constraint-attributes    #9491      +/-   ##
=====================================================================
+ Coverage                              82.50%   82.51%   +0.01%     
=====================================================================
  Files                                    467      467              
  Lines                                  66127    66133       +6     
=====================================================================
+ Hits                                   54555    54567      +12     
+ Misses                                 11572    11566       -6     
Files with missing lines Coverage Δ
compiler/frontend/bs_ast_invariant.ml 93.75% <100.00%> (-1.25%) ⬇️
compiler/frontend/ppx_entry.ml 92.30% <100.00%> (+0.64%) ⬆️
compiler/typing/builtin_attributes.ml 86.13% <100.00%> (+2.46%) ⬆️
compiler/typing/inline_not_stored.ml 93.33% <100.00%> (-0.42%) ⬇️
compiler/typing/translcore.ml 88.48% <100.00%> (-0.03%) ⬇️
compiler/typing/translmod.ml 95.65% <100.00%> (+0.11%) ⬆️
compiler/typing/typecore.ml 89.16% <100.00%> (ø)
compiler/typing/typedtree.ml 91.80% <100.00%> (+0.57%) ⬆️
compiler/typing/typemod.ml 77.64% <100.00%> (-0.06%) ⬇️

... and 1 file with indirect coverage changes

🚀 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.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 655,167,683 → 655,193,894 (±0.00%).

Generated projects: 627,289,701 → 627,355,390 (+0.01%).

Benchmark Base Head Change
packages/@rescript/belt/src/Belt.res 188,591 189,012 +0.22%
build/Namespace/edit 7,906,357 7,920,397 +0.18%
packages/@rescript/runtime/Stdlib_Ordering.res 152,935 152,668 -0.17%
packages/@rescript/runtime/JsxDOMStyle.res 1,926,300 1,923,696 -0.14%
packages/@rescript/runtime/Dom_storage.res 166,280 166,061 -0.13%
packages/@rescript/runtime/Stdlib_String.res 499,496 498,933 -0.11%
packages/@rescript/runtime/Primitive_module.res 326,678 327,026 +0.11%

Instructions

In total: 9,128,461,676 → 9,129,986,150 (+0.02%).

Benchmark Base Head Change
stress/ListLiteral.res 129,281,329 129,429,576 +0.11%

Output size

In total: 27,368,926 → 27,369,214 (±0.00%).

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

Pull request d9aebad compared with base 64cd1e0 in this run.

@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from 281f0bd to 31ae28c Compare December 1, 2026 18:26
@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9491

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9491

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9491

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9491

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9491

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9491

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9491

commit: d9aebad

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

@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-01T20:37:14.590327Z d9aebad 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31ae28c61c

ℹ️ 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".

Comment thread compiler/frontend/bs_ast_invariant.ml Resolved
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a5815ff9f

ℹ️ 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".

Comment thread compiler/frontend/ppx_entry.ml Resolved
@cknitt cknitt changed the title Report a malformed @warning payload only once Fix malformed @warning payloads reported several times Dec 1, 2026
@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from 8ebf4d5 to 64174bf Compare December 1, 2026 19:42
@cknitt
cknitt added this pull request to stack #9496 December 1, 2026 19:44
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt removed this pull request from stack #9496 December 1, 2026 19:46
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 64174bfb76

ℹ️ 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".

@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from 64174bf to dbe39ca Compare December 1, 2026 19:47
@cknitt cknitt changed the title Fix malformed @warning payloads reported several times Fix @warning reported several times and ignored in translation Dec 1, 2026
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: dbe39ca944

ℹ️ 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".

@cknitt
cknitt changed the base branch from master to fix-printer-constraint-attributes December 1, 2026 19:58
@cknitt
cknitt added this pull request to stack #9499 December 1, 2026 19:58
@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from dbe39ca to 277442c Compare December 1, 2026 19:58
@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from 277442c to f71f99a Compare December 1, 2026 20:04
Why:
    Builtin_attributes.warning_attribute both applied a warning setting
    and reported problems with it. The type checker enters a binding's
    warning scope once for each of its passes, 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 left its warning state
    in place for the type checker and translation.

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

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, including the second pass over a recursive module, the frontend,
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 type checking starts from the command
line's warning state, in one-step compiles as in builds.

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, includes and expression statements
get a scope of their attributes, and the scope of a binding also covers
the checks of its @inline attribute. 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 (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

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)

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>
@cknitt
cknitt force-pushed the fix-malformed-warning-repeat branch from f71f99a to d9aebad Compare December 1, 2026 20:21
@cknitt

cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d9aebad3fe

ℹ️ 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".

@cknitt
cknitt marked this pull request as ready for review December 1, 2026 20:47
@cknitt
cknitt requested a review from cristianoc December 1, 2026 20:48
@cknitt
cknitt merged commit 4609ee3 into master Dec 2, 2026
37 of 38 checks passed
@cknitt
cknitt deleted the fix-malformed-warning-repeat branch December 2, 2026 06:10
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.

A malformed @warning payload is reported up to six times

2 participants