Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Assign Oneof Variant to Field with Oneof Type #48

Open
swork1 opened this issue Mar 1, 2024 · 2 comments
Open

Unable to Assign Oneof Variant to Field with Oneof Type #48

swork1 opened this issue Mar 1, 2024 · 2 comments

Comments

@swork1
Copy link
Contributor

swork1 commented Mar 1, 2024

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?

@JasonSteving99
Copy link
Owner

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 JasonSteving99 changed the title Type error? Unable to Assign Oneof Variant to Field with Oneof Type Mar 2, 2024
@swork1
Copy link
Contributor Author

swork1 commented Mar 2, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants