Require const generic literals to be wrapped in Literal #367

Merged
sb10q merged 7 commits from enhance/typing-literal into master 2023-12-16 18:40:48 +08:00

7 Commits

Author SHA1 Message Date
David Mak a4ee2ae22e core: Remove redundant argument in type annotation parsing 2023-12-15 12:26:47 +08:00
David Mak 2722a7a17f core: Do not keep unification result for function arguments
For some reason, when unifying a function call parameter with an
argument, subsequent calls to the same function will only accept the
type of the substituted argument.

This affect snippets like:

```
def make1() -> C[Literal[1]]:
    return ...

def make2() -> C[Literal[2]]:
    return ...

def consume(instance: C[Literal[1, 2]]):
    pass

consume(make1())
consume(make2())
```

The last statement will result in a compiler error, as the parameter of
consume is replaced with C[Literal[1]].

We fix this by getting a snapshot before performing unification, and
restoring the snapshot after unification succeeds.
2023-12-15 12:26:47 +08:00
David Mak bf830f216e core: Deduplicate values in `Literal`
Matches the behavior with `typing.Literal`.
2023-12-15 12:26:43 +08:00
David Mak f742d0c32d core: Refactor generic constants to `Literal`
Better matches the syntax of `typing.Literal`.
2023-12-15 12:20:45 +08:00
David Mak 875d08e9bb core: Add PrimitiveStore into Unifier
This will be used during unification between a const generic variable
and a `Literal`.
2023-12-15 12:20:44 +08:00
David Mak 8d47d6d4dd core: Fix indentation 2023-12-13 18:15:22 +08:00
David Mak a6331ef88b standalone: Output id of undefined identifier 2023-12-13 13:26:14 +08:00