diff --git a/ada/ast.py b/ada/ast.py index 6c752e220..1dc7c6927 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -10085,17 +10085,24 @@ def xref_equation(): ), Entity.id.name_is('Warnings'), - Entity.args.at(1)._.assoc_expr.then( - lambda expr: If( - expr.is_a(T.Identifier), - - expr.sub_equation, + Entity.args.logic_all( + lambda arg: arg.assoc_expr.then( + lambda expr: If( + expr.is_a(T.Identifier), + If( + expr.cast(T.Identifier)._.name_symbol.any_of( + 'On', 'Off', 'GNAT', 'GNATprove' + ), + LogicTrue(), + expr.sub_equation + ), - Bind(expr.expected_type_var, Self.std_entity("String")) - & expr.sub_equation - & expr.matches_expected_type - ), - default_val=LogicTrue() + Bind(expr.expected_type_var, Self.std_entity("String")) + & expr.sub_equation + & expr.matches_expected_type + ), + default_val=LogicTrue() + ) ), # Pragmas we want to deliberately not resolve, either because there diff --git a/testsuite/tests/name_resolution/pragma_warnings/test.adb b/testsuite/tests/name_resolution/pragma_warnings/test.adb new file mode 100644 index 000000000..cf4a2dbd1 --- /dev/null +++ b/testsuite/tests/name_resolution/pragma_warnings/test.adb @@ -0,0 +1,12 @@ +procedure Test is + pragma Warnings (GNATprove, On, "a warning"); + pragma Test_Statement; + pragma Warnings (GNAT, Off, "a warning"); + pragma Test_Statement; + pragma Warnings (Off, "a warning"); + pragma Test_Statement; + pragma Warnings (Off); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/pragma_warnings/test.out b/testsuite/tests/name_resolution/pragma_warnings/test.out new file mode 100644 index 000000000..1f25ee1d2 --- /dev/null +++ b/testsuite/tests/name_resolution/pragma_warnings/test.out @@ -0,0 +1,73 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +******************************************************* + +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: + expected type: + +Resolving xrefs for node +******************************************************* + +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: + expected type: + +Resolving xrefs for node +******************************************************* + +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: + expected type: + +Resolving xrefs for node +******************************************************* + +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: None + expected type: None + + +Done. diff --git a/testsuite/tests/name_resolution/pragma_warnings/test.yaml b/testsuite/tests/name_resolution/pragma_warnings/test.yaml new file mode 100644 index 000000000..173e325ff --- /dev/null +++ b/testsuite/tests/name_resolution/pragma_warnings/test.yaml @@ -0,0 +1,2 @@ +driver: name-resolution +input_sources: [test.adb] diff --git a/user_manual/changes/libadalang/1069.yaml b/user_manual/changes/libadalang/1069.yaml new file mode 100644 index 000000000..7f48d92e7 --- /dev/null +++ b/user_manual/changes/libadalang/1069.yaml @@ -0,0 +1,6 @@ +type: bugfix +title: Fix ``pragma Warnings`` name resolution +description: | + This change fixes a name resolution bug for the pragma `Warnings` by not + trying to resolve reserved words such as `On`, `Off`, `GNAT` or `GNATprove`. +date: 2023-09-08