@@ -8,41 +8,52 @@ fun is_assigned(id, body) =
88 |" statement in the provided HandledStatements.
99 {
1010 # Get the statements in the subp body and its exception handlers
11- val stmts = body.f_stmts.children
12- & concat([eh.f_stmts.children
13- for eh in body.f_exceptions.children
14- if eh is ExceptionHandler].to_list);
15- stdlib.any([s is AssignStmt when s.f_dest.p_referenced_defining_name == id
16- for s in stmts])
11+ val stmts = body.f_stmts.children & concat([
12+ eh.f_stmts.children
13+ for eh in body.f_exceptions.children
14+ if eh is ExceptionHandler
15+ ].to_list);
16+ stdlib.any([
17+ s.f_dest.p_referenced_defining_name() == id
18+ for s in stmts
19+ if s is AssignStmt
20+ ])
1721 }
1822
1923fun is_unconstrained_discriminated(type_decl) =
2024 |" Get if the given BaseTypeDecl is an unconstrained type with a default valued
2125 |" discriminant.
2226 match type_decl
23- | SubtypeDecl => not type_decl.f_subtype.p_subtype_constraint()
24- and is_unconstrained_discriminated(type_decl.p_get_type())
25- | BaseTypeDecl(p_base_type(): not null)
26- => not type_decl.f_type_def.f_subtype_indication.p_subtype_constraint()
27- and is_unconstrained_discriminated(type_decl.p_base_type())
28- | BaseTypeDecl(p_private_completion(): not null)
29- => is_unconstrained_discriminated(type_decl.p_private_completion())
27+ | SubtypeDecl => not type_decl.f_subtype.p_subtype_constraint()
28+ and is_unconstrained_discriminated(type_decl.p_get_type())
29+ | BaseTypeDecl(
30+ p_base_type(): not null
31+ ) => not type_decl.f_type_def.f_subtype_indication.p_subtype_constraint()
32+ and is_unconstrained_discriminated(type_decl.p_base_type())
33+ | BaseTypeDecl(
34+ p_private_completion(): not null
35+ ) => is_unconstrained_discriminated(type_decl.p_private_completion())
3036 # TODO: Remove the 'p_discriminants_list' parameter when langkit#776 will be resolved
31- | BaseTypeDecl => stdlib.any([d.f_default_expr != null
32- for d in type_decl.p_discriminants_list(type_decl.p_root_type())])
33- | * => false
37+ | BaseTypeDecl => stdlib.any([
38+ d.f_default_expr != null
39+ for d in type_decl.p_discriminants_list(type_decl.p_root_type())
40+ ])
41+ | * => false
3442
3543@check(help="possible occurrence of KP 19142",
3644 message="possible occurrence of KP 19142")
3745fun kp_19142(node) =
3846 node is SubpBody
3947 # Check that the subprogram is overriding
4048 when node.p_root_subp_declarations()
41- # Check that the subprogram hasn't been declared earlier, otherwise the KP
42- # won't happen.
43- and not node.p_decl_part()
44- and stdlib.any([stdlib.any([is_assigned(id, node.f_stmts)
45- for id in p.f_ids.children])
46- for p in node.f_subp_spec.p_params()
47- if is_unconstrained_discriminated(p.p_formal_type())
48- and p.f_mode is (ModeOut | ModeInOut)])
49+ # Check that the subprogram hasn't been declared earlier, otherwise the KP
50+ # won't happen.
51+ and not node.p_decl_part()
52+ and stdlib.any([
53+ stdlib.any([
54+ is_assigned(id, node.f_stmts) for id in p.f_ids.children
55+ ])
56+ for p in node.f_subp_spec.p_params()
57+ if is_unconstrained_discriminated(p.p_formal_type())
58+ and p.f_mode is (ModeOut | ModeInOut)
59+ ])
0 commit comments