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

Call operator fails to bind across imports #23901

Open
Nycto opened this issue Jul 28, 2024 · 2 comments
Open

Call operator fails to bind across imports #23901

Nycto opened this issue Jul 28, 2024 · 2 comments

Comments

@Nycto
Copy link
Contributor

Nycto commented Jul 28, 2024

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: 5935c3b
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
Copy link
Collaborator

beef331 commented Jul 28, 2024

Compiling with --experimental:callOperator instead works as intended

@Nycto
Copy link
Contributor Author

Nycto commented Jul 28, 2024

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.

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

No branches or pull requests

3 participants