diff options
author | metagn <metagngn@gmail.com> | 2024-06-25 16:49:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-25 15:49:43 +0200 |
commit | 948fc29bb20018437678e7c11019f1f2455c3a72 (patch) | |
tree | fa2313a97e7de6e1581d0f547b76cc76ed9568ce | |
parent | 2c83f94544b9acc6d06fd6b7fcf035e5cb0aa8eb (diff) | |
download | Nim-948fc29bb20018437678e7c11019f1f2455c3a72.tar.gz |
adapt semOpAux to opt-in symchoices (#23750)
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.
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | tests/lookups/t23749.nim | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 10695ed1d..4507a15ae 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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: diff --git a/tests/lookups/t23749.nim b/tests/lookups/t23749.nim new file mode 100644 index 000000000..650f04ea4 --- /dev/null +++ b/tests/lookups/t23749.nim @@ -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() |