zer0-star / nim-curry

MIT License
12 stars 0 forks source link

Currying fails with `auto` return type #2

Open thenjip opened 2 years ago

thenjip commented 2 years ago

Description

Currying a proc definition returning auto makes the compilation fail.

Example code

import pkg/[nim_curry]

proc f(a: int; b: int): auto {.curry.} =
  0

echo(f(1)(2))

Current result

Compilation fails with:

xxx.nim(6, 5) Error: type mismatch: got <untyped>
but expected one of:
proc echo(x: varargs[typed, `$`])
  first type mismatch at position: 1
  required type for x: varargs[typed]
  but expression 'f(1)(2)' is of type: untyped

Expected result

f after currying should have the type int -> (int -> auto). Printing f.typeof() gives proc (a: int): proc (b: int): untyped{.closure.}{.noSideEffect, gcsafe, locks: 0.}.

Software used

Additional context

I first found out about this after trying to curry a lambda expression like so:

import pkg/[nim_curry]

let f = proc (a, b: int): auto {.curry.} = 0

echo(f(1)(2))

If this bug is fixed, it may enable writing lambda expressions the shorter way: (a: int, b: int) {.curry.} => 0.