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

Regression: ambiguous identifier #23749

Closed
narimiran opened this issue Jun 21, 2024 · 0 comments · Fixed by #23750
Closed

Regression: ambiguous identifier #23749

narimiran opened this issue Jun 21, 2024 · 0 comments · Fixed by #23750

Comments

@narimiran
Copy link
Member

narimiran commented Jun 21, 2024

Description

This is a minimized, self-contained example of a code that works with Nim 2.0.6 and Nim 1.6.20, but it fails with Nim devel:

{.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()

git bisect shows commit 5f9038a5d, i.e. PR #22716 as a first failing commit. (ping @metagn)

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-20
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 646bd99
active boot switches: -d:release

Current Output

Error: ambiguous identifier 'decode' -- use one of the following:
  getSnappySSZ.decode: proc (data: openArray[byte]){.closure, noSideEffect, gcsafe.}
  filename.decode: proc (input: openArray[byte], maxSize: int): seq[byte]{.noSideEffect, gcsafe.}

Expected Output

compiles

Possible Solution

No response

Additional Information

No response

metagn added a commit to metagn/Nim that referenced this issue Jun 21, 2024
@Araq Araq closed this as completed in 948fc29 Jun 25, 2024
narimiran pushed a commit that referenced this issue Aug 14, 2024
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.

(cherry picked from commit 948fc29)
narimiran pushed a commit that referenced this issue Aug 14, 2024
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.

(cherry picked from commit 948fc29)
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

Successfully merging a pull request may close this issue.

1 participant