nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

Regression: ambiguous identifier #23749

Closed narimiran closed 3 days ago

narimiran commented 1 week ago

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 https://github.com/nim-lang/Nim/pull/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: 646bd99d461469f08e656f92ae278d6695b35778 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