acton
acton copied to clipboard
Named tuples type inference broken
Acton Version
0.22.0.20240426.8.47.57
Steps to Reproduce and Observed Behavior
actor main(env):
# Items in a tuple can be of different types
t = ("foo", 42)
# Fields are accessed by their index and using field / attribute selection style:
print(t)
print(t.0)
print(t.1)
# Tuples can use named fields
nt = (a="bar", b=1337)
print(nt)
print(nt.a)
print(nt.b)
env.exit(0)
actonc fails to infer the type of the named tuple nt, like so:
Building project in /home/user/foo
Compiling example.act for release
ERROR: Error when compiling example module: Type error
Cannot satisfy the following simultaneous constraints for the unknown types t0, t1:
|
15 | print(nt.b)
| ^^
The type of the indicated expression (which we call t0) must have an attribute b with type _; no such type is known.
|
14 | print(nt.a)
| ^^
The type of the indicated expression (which we call t0) must have an attribute a with type _; no such type is known.
|
12 | nt = (a="bar", b=1337)
| ^^^^
The type of the indicated expression (which we call t1) must implement __builtin__.Number
|
12 | nt = (a="bar", b=1337)
| ^^^^^^^^^^^^^^^^^
The type of the indicated expression (inferred to be (a: __builtin__.str, b: t1)) must be a subclass of t0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
actonc exited with code: 1 terminated with signal: 0
adding an explicit type signature fixes it.
Expected Behavior
Success