Skip to content

fix(golike): register generic functions with [...] type params#484

Open
StressTestor wants to merge 1 commit into
terryyin:masterfrom
StressTestor:fix/golike-generic-type-params
Open

fix(golike): register generic functions with [...] type params#484
StressTestor wants to merge 1 commit into
terryyin:masterfrom
StressTestor:fix/golike-generic-type-params

Conversation

@StressTestor

Copy link
Copy Markdown
Contributor

what

generic functions/methods with a square-bracket type-param list were dropped or mis-parsed (no name, wrong param count). this registers them correctly.

def identity[T](x: T): T = { x }   // before: not counted at all
func Map[T any](x T) T { return x }   // same

why

in golike.py, after a function name _expect_function_dec only handled ( (value params) and < (the <> generics). a [ - Scala def f[T](...) or Go 1.18 func F[T any](...) - fell through to the else and bailed back to _state_global, so the function was never registered. this affects every golike-based reader: go, scala, kotlin, rust, swift, zig, solidity.

fix

one branch in _expect_function_dec that skips the [...] list via _generalize_type_params, mirroring the existing <> _generalize. once the type params are skipped, the following ( params register the function as normal.

tests

  • testScala.py: generic method with one type param, with multiple type params, and a generic method inside a class body (the drop-in-context case)
  • testGo.py: [T any] and multiple type params [T any, U any]

known limitation

this covers the common def f[T](...) / func F[T any](...) shape. paren-less generic defs like Scala def empty[T]: List[T] are still dropped, same as the existing paren-less-def limitation - out of scope here, since closing it means changing how paren-less defs register in general.

Generic functions/methods with a square-bracket type-parameter list were
silently dropped. In golike.py, _expect_function_dec only handled '('
(value params) and '<' (the <> generics); a '[' (Scala def f[T](...), Go
1.18 func F[T any](...)) fell through to the else and bailed to
_state_global, so the function was never registered.

Adds a '[' branch + _generalize_type_params skipping the [...] list,
mirroring the existing <> _generalize, so the following '(' params
register the function. Affects all golike readers: go, scala, kotlin,
rust, swift, zig, solidity.

Covers the common def f[T](...) / func F[T any](...) shape; paren-less
generic defs remain dropped (same as the pre-existing paren-less-def
limitation).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant