Skip to content

Commit

Permalink
adapt semOpAux to opt-in symchoices (#23750)
Browse files Browse the repository at this point in the history
fixes #23749, refs #22716

`semIndirectOp` is used here because of the callback expressions, in
this case `db.getProc(...)`, and `semIndirectOp` calls `semOpAux` to
type its arguments before overloading starts. Hence it can opt in to
symchoices since overloading will resolve them.
  • Loading branch information
metagn authored Jun 25, 2024
1 parent 2c83f94 commit 948fc29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = isOpImpl(c, n, flags)

proc semOpAux(c: PContext, n: PNode) =
const flags = {efDetermineType}
const flags = {efDetermineType, efAllowSymChoice}
for i in 1..<n.len:
var a = n[i]
if a.kind == nkExprEqExpr and a.len == 2:
Expand Down
37 changes: 37 additions & 0 deletions tests/lookups/t23749.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
discard """
action: compile
"""

{.pragma: callback, gcsafe, raises: [].}

type
DataProc* = proc(val: openArray[byte]) {.callback.}
GetProc = proc (db: RootRef, key: openArray[byte], onData: DataProc): bool {.nimcall, callback.}
KvStoreRef* = ref object
obj: RootRef
getProc: GetProc

template get(dbParam: KvStoreRef, key: openArray[byte], onData: untyped): bool =
let db = dbParam
db.getProc(db.obj, key, onData)

func decode(input: openArray[byte], maxSize = 128): seq[byte] =
@[]

proc getSnappySSZ(db: KvStoreRef, key: openArray[byte]): string =
var status = "not found"
proc decode(data: openArray[byte]) =
status =
if true: "found"
else: "corrupted"
discard db.get(key, decode)
status


var ksr: KvStoreRef
var k = [byte(1), 2, 3, 4, 5]

proc foo(): string =
getSnappySSZ(ksr, toOpenArray(k, 1, 3))

echo foo()

0 comments on commit 948fc29

Please sign in to comment.