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.41k stars 1.47k forks source link

Call operator fails to bind across imports #23901

Open Nycto opened 1 month ago

Nycto commented 1 month ago

Description

The callOperator fails to bind when the usage and declaration are spread across two different files. For example:

##
## myLib.nim
##
type
    Functor* = ref object
        callback: proc(): string

{.experimental: "callOperator".}
proc `()`*(comp: Functor): string = comp.callback()

and

##
## entry.nim
##
import myLib

type
    Bundle = object
        exec: Functor

proc someProc*(control: Bundle) =
    echo control.exec()

However, the same code does work when the import is removed:

type
    Functor* = ref object
        callback: proc(): string

{.experimental: "callOperator".}
proc `()`*(comp: Functor): string = comp.callback()

type
    Bundle = object
        exec: Functor

proc someProc*(control: Bundle) =
    echo control.exec()

Nim Version

Nim Compiler Version 2.0.8 [Linux: amd64] Compiled at 2024-07-03 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf active boot switches: -d:release

Current Output

/tmp/testing/entry.nim(8, 17) Error: attempting to call undeclared routine: 'exec'

Expected Output

Expect it to compile

Possible Solution

No response

Additional Information

No response

beef331 commented 1 month ago

Compiling with --experimental:callOperator instead works as intended

Nycto commented 1 month ago

Ah, interesting. I suppose this bug report is really about error messaging, then. It would be helpful if the error expressed that adding the correct flags would fix the problem.