claro-lang
claro-lang copied to clipboard
Unable to Assign Oneof Variant to Field with Oneof Type
The following does not compile giving Invalid type: Found: LIST Expected: oneof<[int], int>
newtype Node : struct {
example: oneof<[int], int>
}
var test = Node({example = [1,2]});
print(test);
Introducing a variable allows it to compile
var l = [1, 2];
var test = Node({example = l});
Is this intended?
Thanks for giving Claro a try! You've run into a known type checking bug unfortunately. There are some rough edges around Claro's current handling of oneof<...>
s in circumstances like this one. Essentially the issue is that Claro's type checking logic is essentially just doing a plain type equality check in this instance ([int]
!= oneof<[int], int>
) whereas it should obviously accept either variant in this case just as it does with the variable assignment.
Even procedure arguments have addressed this issue, as the below works as well:
function getNode(e: oneof<[int], int>) -> Node {
return Node({example = e});
}
So, thanks for reporting this, you're right that it should be addressed.
Awesome, thanks for getting back to me! I'm enjoying Claro so far! Learning Bazel is also new to me but I'm very impressed by how much it can accomplish (learning curve is there though)