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

GCC incompatible type error when passing generated closure function stored in const #21286

Closed
hamidb80 opened this issue Jan 20, 2023 · 2 comments

Comments

@hamidb80
Copy link
Contributor

hamidb80 commented Jan 20, 2023

Description

import std/[algorithm, sugar]

proc genFn(c: int): auto =
  return proc (a, b: int): int =
    c # [error]
    # 1 # [works fine]

const fn = genFn 1 # [error]
# const fn = (a, b: int) => 1 # [works fine]
# let fn = genFn 1 # [works fine]

echo sorted(@[5, 7, 1], fn)

Nim Version

1.6.10

Current Output

C:\Users\HamidB80\nimcache\play_d\@mplay.nim.c:115:70: error: 'T3_' undeclared here (not in a function)
 N_LIB_PRIVATE NIM_CONST tyProc__EGDHMEKq2nFyDlkU6lrC3A fn__play_42 = T3_;
                                                                      ^~~
C:\Users\HamidB80\nimcache\play_d\@mplay.nim.c: In function 'NimMainModule':
C:\Users\HamidB80\nimcache\play_d\@mplay.nim.c:226:49: error: incompatible types when assigning to type 'void *' from type 'tyObject_Env_playdotnim_genFn___9cbEZv2HaI6Rv8hCkO7M63Q' {aka 'const struct tyObject_Env_playdotnim_genFn___9cbEZv2HaI6Rv8hCkO7M63Q'}
  T3_.ClP_0 = colonanonymous___play_6; T3_.ClE_0 = TM__r9bkcJ6PRJ5n7ORNxxJ5ryg_2;

Expected Output

compiles successfully

Possible Solution

No response

Additional Information

No response

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jan 22, 2023

it works with static int though

- proc genFn(c: int): auto =
+ proc genFn(c: static int): auto =

@ringabout
Copy link
Member

Duplicate of #16534

@ringabout ringabout marked this as a duplicate of #16534 Jan 25, 2023
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

No branches or pull requests

2 participants