Skip to content

Mixed na { } block: str-param function crashes with ctypes error when block also has container-param siblings #7507

Description

@marsninja

Summary

An embedded na function taking a str parameter falls back to Python cleanly when it is alone, but dies at run time with a ctypes error when it shares an na { } block with functions that take list[int]/dict parameters. The per-function native/fallback decision appears to be poisoned by block-mates.

Repro (crashes)

na {
    def shout(s: str) -> str { return s.upper(); }
    def total(xs: list[int]) -> int { s = 0; for x in xs { s += x; } return s; }
    def pick(d: dict[str, int], k: str) -> int { return d[k]; }
}
with entry { print(shout("hi")); }

TypeError: 'str' object cannot be interpreted as ctypes.c_char_p at shout().

Contrast (works)

na def shout(s: str) -> str { return s.upper(); } standalone → falls back cleanly, prints HI.

Analysis

The native calling convention is attempted for shout (a function that should have fallen back to Python), producing a ctypes marshalling crash. The presence of container-taking siblings in the same block changes the per-function lowering/fallback decision. Found on 0.32.0 while verifying book listings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions