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

gensym anonymous proc symbols #24422

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
of nkEmpty:
s = newSym(kind, c.cache.idAnon, c.idgen, c.getCurrOwner, n.info)
s.flags.incl sfUsed
s.flags.incl sfGenSym
n[namePos] = newSymNode(s)
of nkSym:
s = n[namePos].sym
Expand Down
41 changes: 41 additions & 0 deletions tests/proc/tanonprocresem.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
block: # issue #19019
proc start(draw:proc=(proc()=echo "default"), init:proc=(proc()=echo "default"), reshape:proc=(proc()=echo "default"))=discard
start()

block: # issue #14067
type
Result[T, E] = object

DataProc = proc(val: openArray[byte])
GetProc = proc (onData: DataProc): Result[bool, cstring]

func get[T, E](self: Result[T, E]): T =
discard

template `[]`[T, E](self: Result[T, E]): T =
self.get()

proc testKVStore() =
var v: seq[byte]
var p: GetProc

discard p(proc(data: openArray[byte]) =
v = @data
)[]

if false: testKVStore()

import std/macros

block: # issue #15004
macro fn(fun:untyped):untyped =
newTree(nnkTupleConstr, newLit"first", fun)

macro fn(key:string, fun:untyped):untyped =
newTree(nnkTupleConstr, newLit"second", fun)

let c = fn(proc(count:int):string =
return "x = " & $count
)
doAssert c[0] == "first"
doAssert c[1](123) == "x = 123"