Skip to content

[check-type] fix faulty #no_nil variants error#2590

Merged
gingerBill merged 1 commit into
odin-lang:masterfrom
inbelic:inbelic/fix-no_nil-variants-err
Jun 14, 2023
Merged

[check-type] fix faulty #no_nil variants error#2590
gingerBill merged 1 commit into
odin-lang:masterfrom
inbelic:inbelic/fix-no_nil-variants-err

Conversation

@inbelic

@inbelic inbelic commented Jun 13, 2023

Copy link
Copy Markdown
Contributor
  • when checking the variants of a union type we will skip adding the variants if we have an unspecialized polymorphic, hence our union_type variants will be empty and have a count of 0

  • so when checking if we violate the #no_nil error, if we are in the unspecialized polymorphic case and there exists at least one variant in the original variants then we should not raise this error

  • test checks that we do not raise the error anymore, and that we still detect the #no_nil error in the described circumstances

fixes #2395

- when checking the variants of a union type we will skip adding
  the variants if we have an unspecialized polymorphic, hence our
  union_type variants will be empty and have a count of 0

- so when checking if we violate the #no_nil error, if we are in the
  unspecialized polymorphic case and there exists at least one variant
  in the original variants then we should not raise this error

- test checks that we do not raise the error anymore, and that we still
  detect the #no_nil error in the described circumstances
@inbelic

inbelic commented Jun 13, 2023

Copy link
Copy Markdown
Contributor Author

Maybe not as apparent, but in the case that we use the same type in the first Invalid example, then we will raise the duplicate variant error and cover that case.

The second if statement that checks the ut->variants.count is to raise the error directly if the union only consists of the polymorphic type. Otherwise, the error would be raised when we try to define an instance of the Union with the specific type. If that is the desired behaviour then we could just remove that if guard.

@inbelic inbelic marked this pull request as ready for review June 13, 2023 20:22
@gingerBill gingerBill merged commit 2149afa into odin-lang:master Jun 14, 2023
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

Successfully merging this pull request may close these issues.

Getting error "A union with #no_nil must have at least 2 variants" for a polymorphic union, even when it has 2 variants

2 participants