claro-lang icon indicating copy to clipboard operation
claro-lang copied to clipboard

Unable to Assign Oneof Variant to Field with Oneof Type

Open swork1 opened this issue 11 months ago • 2 comments

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?

swork1 avatar Mar 01 '24 04:03 swork1

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.

JasonSteving99 avatar Mar 02 '24 01:03 JasonSteving99

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)

swork1 avatar Mar 02 '24 04:03 swork1