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

Function type alias and c codegen error #3386

Closed
vegansk opened this issue Sep 29, 2015 · 1 comment
Closed

Function type alias and c codegen error #3386

vegansk opened this issue Sep 29, 2015 · 1 comment

Comments

@vegansk
Copy link
Contributor

vegansk commented Sep 29, 2015

This code:

import future

type
  Func0*[R] = () -> R
  # This definition fails too
  # Func0*[R] = proc(): R

# This definition leads to error
proc memoize*[T](f: Func0[T]): Func0[T] =
# And this is not
# proc memoize*[T](f: () -> T): () -> T =
  ## Create function's value cache (not thread safe yet)
  var hasValue = false
  var value: T
  result = proc(): T =
    if not hasValue:
      hasValue = true
      value = f()
    return value

when isMainModule:
  var x = 0
  let f = () => (
    inc x;
    x
  )
  let fm = f.memoize
  echo f()
  echo fm()
  echo f()
  echo fm()

fails to compile:

/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c: In function ‘HEX3Aanonymous_101125’:
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c:341:37: error: called object is not a function or function pointer
   (*HEX3Aenvp_101135).value101124 = (*HEX3Aenvp_101135).f101120();
                                     ^
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c: In function ‘functionsInit000’:
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c:478:9: error: called object ‘fm_101142’ is not a function or function pointer
  LOC4 = fm_101142();
         ^
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c:237:13: note: declared here
 Func0101113 fm_101142;
             ^
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c:490:9: error: called object ‘fm_101142’ is not a function or function pointer
  LOC8 = fm_101142();
         ^
/home/vega/work/nim/nimfp/src/fp/nimcache/nimfp_functions.c:237:13: note: declared here
 Func0101113 fm_101142;
             ^

@vegansk
Copy link
Contributor Author

vegansk commented Jan 18, 2016

It seems, that it is already fixed in devel. Closing...

@vegansk vegansk closed this as completed Jan 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants