exaloop / exaloop/codon

Typechecker rejects callable argument in virtual method call

Open
#850 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
603
Avg merge
4d 23h
Merged PRs (30d)
6

Description

The compiler fails to typecheck this program:

```python
class A:
def f(self, block: CallableTrait[[], bool]):
return False

class B(A):
def f(self, block: CallableTrait[[], bool]):
return block()

def make_base() -> A:
return B()

print(make_base().f(lambda: False or True))
print(make_base().f(lambda: True and False))
```
B inherits from A. The function `make_base` is annotated as returning A, but it actually returns an instance of B.
So it should dispatch to `B.f`, execute the passed lambda, and return the lambda result.
However, it looks like the program fails during typechecking before it can get as far as calling either A.f or B.f.

### Result
```bash
$ codon run -release 04_factory_base_return_callable.codon
04_factory_base_return_callable.codon:15 (1-44): error: cannot typecheck 'print(make_base().f(lambda: False or True))'
04_factory_base_return_callable.codon:16 (1-45): error: cannot typecheck 'print(make_base().f(lambda: True and False))'
```
Expected to print:
```
True
False
```

Contributor guide

Open the contributing guide

Research direction

Start by running 04_factory_base_return_callable.codon with the reported codon run -release command and inspect the typechecking path for the two virtual calls using CallableTrait arguments. Done means the program typechecks and prints True followed by False, as shown in the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.