Skip to content

declarations

Preserve the public declaration-handler import path while the split declaration mixins live in the private _declarations package.

Classes:

DeclarationVisitorMixin

Bases: DeclarationFunctionVisitorMixin, DeclarationStructVisitorMixin, DeclarationClassSupportVisitorMixin, DeclarationClassLayoutVisitorMixin, DeclarationClassMemberVisitorMixin, DeclarationBlockVisitorMixin

Compose the declaration-focused semantic mixins so the analyzer keeps the same visitor surface while the implementation stays split by concern.

Methods:

visit

visit(node: FunctionDef) -> None
Source code in packages/irx/src/irx/analysis/handlers/_declarations/functions.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
@SemanticAnalyzerCore.visit.dispatch
def visit(self, node: astx.FunctionDef) -> None:
    """
    title: Visit FunctionDef nodes.
    parameters:
      node:
        type: astx.FunctionDef
    """
    for template_param in astx.get_template_params(node.prototype):
        self._resolve_declared_type(template_param.bound, node=node)
    for arg in node.prototype.args.nodes:
        self._resolve_declared_type(arg.type_, node=arg)
    self._resolve_declared_type(node.prototype.return_type, node=node)
    function = self.registry.resolve_function(node.name)
    if function is None:
        function = self.registry.register_function(
            node.prototype,
            definition=node,
        )
    function = self._synchronize_function_signature(
        function,
        node.prototype,
        definition=node,
    )
    self.bindings.bind_function(node.name, function, node=node)
    self._set_function(node.prototype, function)
    self._set_function(node, function)
    generator = self._resolve_generator_function(function, node)
    if function.template_params:
        self._set_type(node.prototype, None)
        self._set_type(node, None)
        return
    with self.context.in_function(function):
        self._analyze_parameter_defaults(function)
        with self.context.scope("function"):
            for arg_node, arg_symbol in zip(
                node.prototype.args.nodes,
                function.args,
            ):
                self.context.scopes.declare(arg_symbol)
                self._set_symbol(arg_node, arg_symbol)
                self._set_type(arg_node, arg_symbol.type_)
            self.visit(node.body)
    if (
        not isinstance(function.return_type, astx.NoneType)
        and generator is None
        and not self._guarantees_return(node.body)
    ):
        self.context.diagnostics.add(
            f"Function '{node.name}' with return type "
            f"'{function.return_type}' is missing a return statement",
            node=node,
        )