From 275256f1569e7d5c98939ccb72a62e109929a44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Tue, 17 Oct 2023 15:57:05 +0200 Subject: [PATCH] Fix CaseExpr xref_equation A case expression does not necessarily have an expected type set by its context. In that case, the expected type for the case expression has to be derived from the case expression's dependent expressions. --- ada/ast.py | 3 +- .../name_resolution/case_expr_3/test.adb | 26 ++++ .../name_resolution/case_expr_3/test.out | 113 ++++++++++++++++++ .../name_resolution/case_expr_3/test.yaml | 2 + 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/name_resolution/case_expr_3/test.adb create mode 100644 testsuite/tests/name_resolution/case_expr_3/test.out create mode 100644 testsuite/tests/name_resolution/case_expr_3/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 729a43856..d1a88da8f 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -16578,7 +16578,8 @@ def xref_equation(): Predicate(BaseTypeDecl.is_not_universal_type, alt.expr.type_var) & Bind(alt.expr.type_var, alt.expr.expected_type_var, - conv_prop=BaseTypeDecl.base_subtype), + conv_prop=BaseTypeDecl.base_subtype) + & Bind(alt.expr.expected_type_var, Self.expected_type_var), LogicTrue() ), LogicTrue() diff --git a/testsuite/tests/name_resolution/case_expr_3/test.adb b/testsuite/tests/name_resolution/case_expr_3/test.adb new file mode 100644 index 000000000..17e5756c0 --- /dev/null +++ b/testsuite/tests/name_resolution/case_expr_3/test.adb @@ -0,0 +1,26 @@ +procedure Test is + procedure P is null; + + type Month is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); + type Employee is (Jan, Jen, Jim, Tim, Tom, Mary, Randy, Ike); + + Selector : Natural := 1; +begin + case (case Selector is + when 0 => Jan, + when 1..8 => Oct, + when others => Dec) is + when Jan => P; + when others => P; + end case; + pragma Test_Statement; + + case (case Selector is + when 0 => Jan, + when 1..8 => Jen, + when others => Jim) is + when Jan => P; + when others => P; + end case; + pragma Test_Statement; +end Test; diff --git a/testsuite/tests/name_resolution/case_expr_3/test.out b/testsuite/tests/name_resolution/case_expr_3/test.out new file mode 100644 index 000000000..6ce0ef3e1 --- /dev/null +++ b/testsuite/tests/name_resolution/case_expr_3/test.out @@ -0,0 +1,113 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +****************************************************** + +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: None +Expr: + type: None + expected type: None +Expr: + references: None + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + type: None + expected type: None +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: +Expr: + type: None + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +******************************************************* + +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: None +Expr: + type: None + expected type: None +Expr: + references: None + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + type: None + expected type: None +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: +Expr: + type: None + expected type: None +Expr: + references: + type: + expected type: + + +Done. diff --git a/testsuite/tests/name_resolution/case_expr_3/test.yaml b/testsuite/tests/name_resolution/case_expr_3/test.yaml new file mode 100644 index 000000000..173e325ff --- /dev/null +++ b/testsuite/tests/name_resolution/case_expr_3/test.yaml @@ -0,0 +1,2 @@ +driver: name-resolution +input_sources: [test.adb]