Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcNotation followed by anonymous fun parameter breaks on macro interpolation #14216

Closed
HertzDevil opened this issue Jan 11, 2024 · 1 comment · Fixed by #14506
Closed

ProcNotation followed by anonymous fun parameter breaks on macro interpolation #14216

HertzDevil opened this issue Jan 11, 2024 · 1 comment · Fixed by #14506

Comments

@HertzDevil
Copy link
Contributor

HertzDevil commented Jan 11, 2024

This is valid code, because parameters of lib funs do not require a name:

lib Foo
  # first parameter is `x : ::Proc(Int, Int)`
  # second parameter is ` : Int`
  fun foo(x : Int -> Int, Int)
end

Macro interpolation of the above AST node adds a pair of parentheses around the ProcNotation restriction:

lib Foo
  fun foo(x : (Int -> Int), Int) # Error: expecting token '->', not ')'
end

It appears the parser is expecting another ProcNotation around those types, e.g.:

fun foo(x : (Int -> Int), Int -> Void) # Proc(Proc(Int, Int), Int, Void)

Either the syntax should allow this, or those parentheses should be dropped. This appears in the Bionic bindings and is not a typo:

# src/lib_c/aarch64-android/c/pthread.cr
lib LibC
  fun pthread_create(__pthread_ptr : PthreadT*, __attr : PthreadAttrT*, __start_routine : Void* -> Void*, Void*) : Int
end

Related: #11966

@HertzDevil
Copy link
Contributor Author

As expected, this applies to normal Calls as well (item 4 on #11966):

macro f(x)
  {{ x.args.map(&.stringify) }}
end

f(foo(x : T, U -> V, Foo))   # => ["x : (T, U -> V)", "Foo"]
f(foo(x : (T, U -> V), Foo)) # Error: expecting token '->', not ')'

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant