@@ -1295,6 +1295,39 @@ def properties_logging(self):
12951295 """
12961296 return any (prop .activate_tracing for prop in self .all_properties )
12971297
1298+ def check_can_reach_signature (self ) -> None :
1299+ """
1300+ Check that the root node's "can_reach" signature is conforming.
1301+ """
1302+ from langkit .compiled_types import T
1303+
1304+ # If the language spec does not create one, the initialisation of the
1305+ # root node is supposed to create an automatic "can_reach" property.
1306+ assert self .root_grammar_class is not None
1307+ fields = self .root_grammar_class .get_abstract_node_data_dict ()
1308+ can_reach = fields ["can_reach" ]
1309+
1310+ qualname = can_reach .qualname
1311+ args = can_reach .natural_arguments
1312+
1313+ with can_reach .diagnostic_context :
1314+ check_source_language (
1315+ can_reach .is_property ,
1316+ f"{ qualname } must be a property" ,
1317+ )
1318+ check_source_language (
1319+ can_reach .type .matches (T .Bool ),
1320+ f"{ qualname } must return a boolean" ,
1321+ )
1322+ check_source_language (
1323+ len (args ) == 1 and args [0 ].type .matches (T .root_node ),
1324+ f"{ qualname } must take one argument: a bare node" ,
1325+ )
1326+ check_source_language (
1327+ not can_reach .uses_entity_info ,
1328+ f"{ qualname } cannot use entities" ,
1329+ )
1330+
12981331 def compute_properties_callgraphs (self ) -> None :
12991332 """
13001333 Compute forwards and backwards properties callgraphs.
@@ -1564,7 +1597,15 @@ def warn(unused_set, message):
15641597 sorted_set = sorted (
15651598 (p .qualname , p )
15661599 for p in unused_set
1567- if not p .is_internal and not p .artificial
1600+ if (
1601+ # Never warn about implicitly referenced properties:
1602+ # internal properties, artificial properties and
1603+ # "can_reach" (can come from the language spec but used by
1604+ # lexical env lookups).
1605+ not p .is_internal
1606+ and not p .artificial
1607+ and p .indexing_name != "can_reach"
1608+ )
15681609 )
15691610 for _ , p in sorted_set :
15701611 with p .diagnostic_context :
@@ -2058,6 +2099,8 @@ def lower_grammar_rules(ctx):
20582099 CompileCtx .compute_uses_entity_info_attr ),
20592100 GlobalPass ('compute uses envs attribute' ,
20602101 CompileCtx .compute_uses_envs_attr ),
2102+ GlobalPass ('check can_reach signature' ,
2103+ CompileCtx .check_can_reach_signature ),
20612104 EnvSpecPass ('check env specs' , EnvSpec .check_spec ),
20622105 GlobalPass ('compute is reachable attribute' ,
20632106 CompileCtx .compute_is_reachable_attr ),
0 commit comments