anistark / anistark/waspy

bug: a bare list or dict annotation loses the element type, so dict keys stop deduplicating

Aberta
#116 0 comentários 0 reações 0 responsáveis Ver no GitHub
bug core-language priority-medium
Linguagem predominante
Rust
Estrelas
22
Forks
6
Merge médio
1d 3h
PRs com merge (30d)
6

Descrição

## Description

A bare `list` or `dict` annotation carries no element type, so a function annotated `-> list` loses it. Downstream, string values from that list compare as untyped words rather than by content, and a dict keyed on them silently fails to deduplicate. Compilation reports success and the count is wrong.

The parameterised forms (`List[str]`, `Dict[str, int]`) work correctly, so this is about what happens when the bare form is used, which is ordinary Python and increasingly the common style since PEP 585.

## Steps to Reproduce

```python
def tokens_bare() -> list:
out = []
for w in "the cat the".split():
out.append(w)
return out

def unique_bare() -> int:
counts = {}
for w in tokens_bare():
counts[w] = 1
return len(counts)
```

`unique_bare()` answers `3`. CPython answers `2`, because `"the"` appears twice.

Changing only the annotation to `-> List[str]` makes the same program answer `2`.

## Environment

- waspy 0.15.0, commit d7dcbc4
- Verified under both `wasmi` (the test harness) and Node 22

## Additional Context

The bare builtin annotations map to collection types whose element type is `Unknown`: https://github.com/anistark/waspy/blob/d7dcbc4/src/ir/converter.rs#L965-L975

Dict keys compare by content only when the key type is known to be a string; with `Unknown` on both sides the comparison falls back to the raw slot word, which for two equal strings built separately is two different offsets.

Two ways out, and they are not exclusive:

1. Infer an element type through a bare annotation where the body makes it clear (the return expression's element type, or what `append` puts in), the way collection fields already get theirs.
2. Say plainly in `README.md` that the parameterised form is required for element types to be known, and reject or warn on a bare annotation whose element type later matters.

The second is the smaller change and would at least stop the wrong answer being silent. `examples/text_report.py` uses the parameterised form for exactly this reason and documents why: https://github.com/anistark/waspy/blob/d7dcbc4/examples/text_report.py

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Start with the bare-annotation handling in src/ir/converter.rs around lines 965-975, then run the reproduction under the wasmi test harness and Node 22. Compare it with the parameterised List[str] case and inspect README.md plus examples/text_report.py. Done means the bare-form behavior no longer silently returns the wrong deduplication count, with the chosen inference or warning/documentation scope made explicit.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python, rust, wasm
Domínio
compilers
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
52/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.