Skip to content

expressions

Resolve lexical identifiers, visible function names, and expression typing rules while delegating reusable registration and binding logic elsewhere.

Classes:

ExpressionVisitorMixin

Bases: SemanticVisitorMixinBase

Methods:

visit

visit(node: SubscriptExpr) -> None
Source code in src/irx/analysis/handlers/expressions.py
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
@SemanticAnalyzerCore.visit.dispatch
def visit(self, node: astx.SubscriptExpr) -> None:
    """
    title: Visit SubscriptExpr nodes.
    parameters:
      node:
        type: astx.SubscriptExpr
    """
    self.visit(node.value)
    if not isinstance(node.index, astx.LiteralNone):
        self.visit(node.index)
    value_type = self._expr_type(node.value)
    if isinstance(node.value, astx.LiteralDict):
        if not node.value.elements:
            self.context.diagnostics.add(
                "SubscriptExpr: key lookup on empty dict",
                node=node,
            )
        elif not isinstance(
            node.index,
            (
                astx.LiteralInt8,
                astx.LiteralInt16,
                astx.LiteralInt32,
                astx.LiteralInt64,
                astx.LiteralUInt8,
                astx.LiteralUInt16,
                astx.LiteralUInt32,
                astx.LiteralUInt64,
                astx.LiteralFloat32,
                astx.LiteralFloat64,
                astx.Identifier,
            ),
        ):
            self.context.diagnostics.add(
                "SubscriptExpr: only integer and floating-point "
                "dict keys are supported",
                node=node,
            )
    self._set_type(
        node,
        cast(
            astx.DataType | None,
            getattr(value_type, "value_type", None),
        ),
    )