Semantic Diff

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

1 commit

738c317473f7c54c688da56c9887f9dbb9cccc71..pr-9491

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

Fix @warning reported several times and ignored in translation

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.

modifiedDiagnostic malformed @warning payload

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

modifiedDiagnostic warning 102 in a module with @warning("-102")

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

Fixes #9488