Semantic Diff

#9495 Fix @warning not applying to warnings from translation

1 commit

64174bfb76eb67addf2d3933f9f2a97116356e27..pr-9495

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

Fix @warning not applying to warnings from translation

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.

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)