Skip to content

Fix directive @warning("-102") not working#8322

Draft
cknitt wants to merge 8 commits intomasterfrom
warning-102
Draft

Fix directive @warning("-102") not working#8322
cknitt wants to merge 8 commits intomasterfrom
warning-102

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented Apr 2, 2026

Fixes #8160.

Symptom

The reported repro was:

let x = (a, b) => {
  @warning("-102") (a->Pair.second > b->Pair.second)
}

With warning 102 enabled, this still produced:

Warning number 102
Polymorphic comparison introduced (maybe unsafe)

Root Cause

Warning 102 (Bs_polymorphic_comparison) was emitted too late, in compiler/core/lam_compile_primitive.ml.

By the time that code ran, local warning scopes created by source attributes such as @warning("-102") had already been restored. As a result, file-wide warning settings still worked, but expression-level suppression did not affect warning 102.

Fix

The warning emission was moved into typedtree-to-lambda translation in compiler/ml/translcore.ml, where it still runs under the relevant source-level warning scopes.

Concretely:

  • warning 102 is emitted when the polymorphic comparison primitive is selected during translation
  • the late warning emission was removed from compiler/core/lam_compile_primitive.ml
  • translation re-enters warning scopes so local source attributes apply at the warning site

This keeps warning 102 enabled by default, while making local suppression behave correctly.

Tests

Regression tests were added under tests/build_tests/super_errors/:

  • warning102_expr_attribute.res
  • warning102_structure_attribute.res
  • warning102_value_attribute.res

These cover:

  • expression-level @warning("-102")
  • file-level @@warning("-102")
  • direct value use such as let v = @warning("-102") compare

All corresponding snapshots are empty, because successful suppression means there is no warning output.

Result

After the fix:

  • @warning("-102") works for local polymorphic comparison expressions
  • @@warning("-102") still works
  • warning 102 still appears normally when no suppression is present

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 2, 2026

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8322

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: c4f4a87

@cknitt
Copy link
Copy Markdown
Member Author

cknitt commented Apr 2, 2026

@codex review

Copy link
Copy Markdown

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

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: 8f4f487f3f

ℹ️ 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
Copy link
Copy Markdown
Member Author

cknitt commented Apr 2, 2026

@codex review

Copy link
Copy Markdown

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

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: 165476741a

ℹ️ 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
Copy link
Copy Markdown
Member Author

cknitt commented Apr 3, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ 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
Copy link
Copy Markdown
Member Author

cknitt commented Apr 3, 2026

@codex review

Copy link
Copy Markdown

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

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: a937c43f73

ℹ️ 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
Copy link
Copy Markdown
Member Author

cknitt commented Apr 3, 2026

@codex review

Copy link
Copy Markdown

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

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: c4f4a87c2d

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

let warning_attribute_iterator =
let structure_item self (structure_item : Parsetree.structure_item) =
(match structure_item.pstr_desc with
| Pstr_attribute attr -> Builtin_attributes.warning_attribute attr
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Limit warning prepass to avoid leaking nested scopes

warning_attribute_iterator now applies every Pstr_attribute/Psig_attribute during a full AST walk, but this mutates the global warning state without any restore. Because this prepass runs before typing, non-leading or nested @@warning directives are effectively active from the start of compilation (and can leak outside their intended scope), so warnings in earlier or outer code can be incorrectly suppressed/enabled; for example, a nested module-level @@warning("-32") can silence outer unused-value warnings.

Useful? React with 👍 / 👎.

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.

@warning("-102") doesn't work

1 participant