diff --git a/ada/ast.py b/ada/ast.py index ff961047d..4981f27db 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -19914,20 +19914,26 @@ def bind_to_prefix_eq(): @langkit_property(return_type=Equation, dynamic_vars=[env, origin]) def result_attr_equation(): - # We find the containing subprogram starting the bound env's node - # instead of Self, as this attribute can appear in a pragma Post - # appearing *after* the subprogram. - containing_subp = Var(env.env_node.parents.find( + # We find the containing declaration (a function declaration or an + # access-to-function type) starting the bound env's node instead of + # Self, as this attribute can appear in a pragma Post appearing + # *after* the declaration. + containing_decl = Var(env.env_node.parents.find( lambda p: p.is_a(BasicSubpDecl, BaseSubpBody) + | p.cast(ConcreteTypeDecl)._.type_def.is_a(AccessToSubpDef) ).as_entity.cast(T.BasicDecl)) - returns = Var(containing_subp.subp_spec_or_null.then( + returns = Var(containing_decl.match( + lambda sd=T.ConcreteTypeDecl: + sd.type_def.cast(AccessToSubpDef).subp_spec, + lambda bd=T.BasicDecl: bd.subp_spec_or_null, + ).then( lambda ss: ss.return_type )) return And( Bind(Self.type_var, returns), - Bind(Entity.prefix.ref_var, containing_subp) + Bind(Entity.prefix.ref_var, containing_decl) ) @langkit_property(return_type=Equation, dynamic_vars=[env, origin]) diff --git a/testsuite/tests/name_resolution/post_result/test.out b/testsuite/tests/name_resolution/post_result/test.out index b849bbef9..fbfee0e20 100644 --- a/testsuite/tests/name_resolution/post_result/test.out +++ b/testsuite/tests/name_resolution/post_result/test.out @@ -72,14 +72,120 @@ Expr: type: None expected type: None -Resolving xrefs for node +Resolving xrefs for node +********************************************************************************** + + +Resolving xrefs for node +******************************************************************** + +Expr: + references: + type: None + expected type: None + +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: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +********************************************************************************** + + +Resolving xrefs for node +******************************************************************** + +Expr: + references: + type: None + expected type: None + +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: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: None + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +****************************************************************** + + +Resolving xrefs for node ****************************************************************** -Expr: +Expr: references: type: None expected type: None -Expr: +Expr: references: type: None expected type: None diff --git a/testsuite/tests/name_resolution/post_result/test_result_attr.adb b/testsuite/tests/name_resolution/post_result/test_result_attr.adb index 837a06cb0..571752de5 100644 --- a/testsuite/tests/name_resolution/post_result/test_result_attr.adb +++ b/testsuite/tests/name_resolution/post_result/test_result_attr.adb @@ -6,6 +6,15 @@ procedure Test_Result_Attr is begin return 12; end Barize; + + type T1 is access function (A : Boolean) return Boolean with + Post => T1'Result = A; + + type T2 is access function (A : Boolean) return Boolean; + + pragma Post (T2'Result = True); + begin + null; end Test_Result_Attr; pragma Test_Block;