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

optional params don't work with block argument(s) in last position #14346

Closed
timotheecour opened this issue May 14, 2020 · 0 comments · Fixed by #18631
Closed

optional params don't work with block argument(s) in last position #14346

timotheecour opened this issue May 14, 2020 · 0 comments · Fixed by #18631

Comments

@timotheecour
Copy link
Member

timotheecour commented May 14, 2020

passing a block as last argument doesn't work with optional params.

This is a common use case; fixing this would simplify a lot of code.

Example

template fun*(a = 1, b = 2, body: untyped) = discard
fun(a = 1, 2): discard
fun(3, 4): discard
fun(b = 5, a = 6): discard
fun(a = 1, body = 1)
fun(a = 1, body = block:
    discard)
fun(a = 1): discard  # CT error
fun(): discard  # CT error

template fun2*(a = 1, b = 2, body: untyped): untyped = (a, b)
let c = fun2(1,2): discard
let c2 = fun2(1): discard # CT error

Current Output

Error: type mismatch: got <a: int literal(1), void>
but expected one of:
template fun(a = 1; b = 2; body: untyped)
  first type mismatch at position: 2
  required type for b: int
  but expression '
discard' is of type: void

expression: fun(a = 1):
  discard
  fun(a = 1): discard  # CT error
     ^

Expected Output

should work

Possible Solution

  • improve sigmatch

Additional Information

links

As the "do" can only fill the arguments starting from the last one, there is no ambiguity in letting the optional arguments before it be left unfiled.

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