Skip to content

invalid code generation when passing closure procedure at compile time #21302

@hamidb80

Description

@hamidb80

Description

proc wrap(fn: static proc: int): proc: int =
  fn

# --- works fine with `normal proc` ---
# proc c1: int = 1
# proc c2: int = 2

const 
  c1 = proc: int = 1
  c2 = proc: int = 2
  
  wrapped_c1 = wrap c1
  wrapped_c2 = wrap c2

when isMainModule: 
  echo c2 == c1  
  echo c2() == c1()
  echo wrapped_c2 == wrapped_c1 
  echo wrapped_c2() == wrapped_c1()
  echo wrapped_c1()
  echo wrapped_c2()

Nim Version

Nim Compiler Version 1.6.10 [Windows: amd64]
Compiled at 2022-11-21

Current Output

false
false
true
true
1
1

Expected Output

false
false
false
false
1
2

Additional Information

without static and const everything works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Static[T]const`const x=expr` or `static: stmt`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions