From ca580b7d0364417762305143de03f713f45cc7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Thu, 11 Jan 2024 16:12:33 +0100 Subject: [PATCH] Fix the Contract_Cases aspect name resolution Only its top level aggregate should use the aspect's special path in the name resolution equation. All other included aggregates have to be resolved the usual way. --- ada/ast.py | 6 +- .../name_resolution/contract_cases/test.adb | 6 ++ .../name_resolution/contract_cases/test.out | 68 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/ada/ast.py b/ada/ast.py index c1b26f0fd..fc93b348d 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -16657,7 +16657,11 @@ def xref_equation(): # as they must all refer to existing declarations. Entity.exprs_assoc_equation, - agg.in_aspect('Contract_Cases'), + # In the case of Contract_Cases aspect, only the top level + # aggregate should be resolved by the special equation here. All + # other agreggates included in the latter should use the regular + # resolution path. + agg.parent.cast(AspectAssoc)._.id.name_is('Contract_Cases'), Entity.contract_cases_assoc_equation, agg.is_a(T.BracketAggregate) & td._.has_aspect('Aggregate'), diff --git a/testsuite/tests/name_resolution/contract_cases/test.adb b/testsuite/tests/name_resolution/contract_cases/test.adb index 158414d9d..93d562ae5 100644 --- a/testsuite/tests/name_resolution/contract_cases/test.adb +++ b/testsuite/tests/name_resolution/contract_cases/test.adb @@ -19,6 +19,12 @@ procedure Test is I > 5 => True, others => False); pragma Test_Block; + + function To_String (S : String) return String is (S); + procedure Qux (S : String) + with Contract_Cases => + [True => To_String (S) = [1 .. 10 => 'C']]; + pragma Test_Block; begin null; end Test; diff --git a/testsuite/tests/name_resolution/contract_cases/test.out b/testsuite/tests/name_resolution/contract_cases/test.out index 6ab46613e..aff323cd5 100644 --- a/testsuite/tests/name_resolution/contract_cases/test.out +++ b/testsuite/tests/name_resolution/contract_cases/test.out @@ -191,5 +191,73 @@ Expr: type: expected type: +Resolving xrefs for node +******************************************************* + + +Resolving xrefs for node +*************************************************************** + +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +*********************************************************** + +Expr: + references: None + type: None + expected type: None +Expr: + type: None + expected type: None +Expr: + references: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: +Expr: + expected type: +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + references: None + type: + expected type: +Expr: + references: + type: + expected type: + Done.