Implement support for Literal with multiple bounds #370

Open
opened 2023-12-18 10:21:04 +08:00 by derppening · 0 comments
Collaborator

Currently, if multiple bounds are specified and unification is naively extended, the following code will fail to compile:

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

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

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

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

with

Incorrect argument type for instance. Expected __main__.ConstGenericClass[const(I32(1))], but got __main__.ConstGenericClass[const(I32(2))]

It appears that after unifying the first call to consume, the parameter type of consume will be substituted with the argument type (i.e. C[Literal[1]]), then the next unification would fail because C[Literal[1]] cannot be unified with C[Literal[2]].

Currently, if multiple bounds are specified and unification is naively extended, the following code will fail to compile: ```py def make1() -> C[Literal[1]]: return ... def make2() -> C[Literal[2]]: return ... def consume(instance: C[Literal[1, 2]]): pass consume(make1()) consume(make2()) ``` with ``` Incorrect argument type for instance. Expected __main__.ConstGenericClass[const(I32(1))], but got __main__.ConstGenericClass[const(I32(2))] ``` It appears that after unifying the first call to `consume`, the parameter type of `consume` will be substituted with the argument type (i.e. `C[Literal[1]]`), then the next unification would fail because `C[Literal[1]]` cannot be unified with `C[Literal[2]]`.
derppening self-assigned this 2023-12-18 10:21:04 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#370
There is no content yet.