[Bug Report] Generic Type Parameter Incorrectly Inferred as NoneType with Lambda Callable
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 603
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
### Environment
- Codon version: v0.19.3
- OS: Debian Bullseye
### Description
Codon fails to correctly infer generic type parameters when a class uses `CallableTrait` with a lambda function. The type parameter is incorrectly inferred as `NoneType` instead of the actual return type of the callable, causing a compilation error.
### Reproduction Code
```python
from collections import Counter
class Item:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
class Count:
Key: type
def __init__(self, project: CallableTrait[[Item], Key]):
self.project = project
self.counter = Counter[Key]()
def visit(self, item: Item):
self.counter[self.project(item)] += 1
items = [Item(1, 2, 3), Item(1, 2, 4), Item(1, 2, 5)]
count = Count(lambda item: item.z) # Lambda returns int
for item in items:
count.visit(item)
print(count)
```
Compilation fails with the following error:
```
crash_on_filter.py:15 (9-13): error: 'Count[NoneType]' object has no attribute 'project'
╰─ crash_on_filter.py:23 (9-35): error: during the realization of __init__(self: Count[NoneType], project: %_lambda_95(...))
```
Contributor guide
Assessment
This issue has not been assessed yet.