Skip to content

Overloading by a local proc affected by code in other blocks #2900

Open
@bluenote10

Description

An issue I discovered while testing this PR. Apparently, the issue is unrelated to the PR, and I couldn't find an existing issue for that. The problem is that overloading by a local proc does work in this example:

import tables
from hashes import THash

block:
  proc hash(x: int): THash {.inline.} =
    echo "overloaded hash"
    result = x

  var t = initTable[int, int]()
  t[0] = 0 # will call the overloaded hash

But if I add another (supposedly unrelated) code block, I can no longer use the overloaded function:

import tables
from hashes import THash

block:
  var t = initTable[int,int]()
  t[0] = 42 # comment this line and it works again!

block:
  proc hash(x: int): THash {.inline.} =
    echo "overloaded hash"
    result = x

  var t = initTable[int, int]()
  t[0] = 0 # now, this no longer calls the overloaded hash!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions