codon icon indicating copy to clipboard operation
codon copied to clipboard

Incorrect behavior observed when calling a method due to local variable name conflicting with an imported module name.

Open learnforpractice opened this issue 2 years ago • 0 comments

I am encountering an issue where the code is not behaving as expected when calling a method in a class.

Here is the relevant code:

a.codon

class A(object):
    pass

test.codon

from a import A

class B(object):
    def say_hello(self):
        print('hello, world from A')

def test():
    a = B()
    a.say_hello()

test()

The code is using a class B that has a method named say_hello, but the method is being recognized as a function from a module a instead of the method in class B. The error message test.codon:9:2-15: error: say_hello() missing 1 required positional argument: 's' is indicating that the method say_hello is being recognized as the function say_hello from module a that requires a positional argument s.

Steps to reproduce:

  1. Run codon run test.codon.

Expected behavior:

The expected output is:

hello, world from A

Actual behavior:

The actual output is:

test.codon:9:2-15: error: say_hello() missing 1 required positional argument: 's'
╰─ test.codon:11:1-5: error: during the realization of test()

learnforpractice avatar Feb 10 '23 06:02 learnforpractice