Skip to content

Bug: _parse_fn_arg_types fails when generic parameter lists contain {...} #232

@terasakisatoshi

Description

@terasakisatoshi

Summary

src/generics.jl locates the function signature with:

fn_pattern = Regex("fn\\s+$(func_name)\\s*(?:<[^{]*?>)?\\s*\\(")

This rejects valid generic parameter lists that contain {...} blocks, such as const-generic defaults or trait bounds with const expressions. In those cases _parse_fn_arg_types returns no argument types even though the signature is otherwise parseable.

Reproducer

using RustCall

RustCall._parse_fn_arg_types(
    "fn foo<const N: usize = { 1 + 2 }, T>(x: T) -> T { x }",
    "foo",
)
# => String[]

RustCall._parse_fn_arg_types(
    "fn foo<T: Trait<{ 1 + 2 }>>(x: T) -> T { x }",
    "foo",
)
# => String[]

Expected

Both calls should return:

["T"]

Actual

The regex fails to match the fn ... <...>( prefix as soon as { appears inside the generic parameter list, so the function returns an empty vector.

Affected Code

  • src/generics.jl:750-758

Notes

Nested generics like Vec<Option<T>> appear to work here because the regex can still backtrack to the final > before (. The failure mode is specifically braces inside the generic parameter list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    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