exaloop / exaloop/codon

[Bug Report] Generic Type Parameter Incorrectly Inferred as NoneType with Lambda Callable

Open
#712 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.