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

fix #19335 Disallow void in type section #20603

Closed
wants to merge 1 commit into from
Closed

Conversation

SirOlaf
Copy link
Contributor

@SirOlaf SirOlaf commented Oct 20, 2022

Fixes #19335

Edit: Other option would be having the field disappear like with generics but that seems confusing

@SirOlaf SirOlaf marked this pull request as draft October 20, 2022 15:30
@SirOlaf SirOlaf marked this pull request as ready for review October 20, 2022 15:33
@Araq
Copy link
Member

Araq commented Oct 20, 2022

No, what we should do instead is to map void to some Unit-like type and optimize it away in the backends.

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

Would that actually address the issue with using a field typed as void and is there a good reason to allow typing a field as void in the first place

@Araq
Copy link
Member

Araq commented Oct 20, 2022

In the example it makes no sense but for

type G[T] = object
  x: T

G[void]

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

Yeah that is the case that makes fields disappear, and it continues to work

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

Actually this presents the question why void can't be modeled as an empty object instead of a special case

type VoidType = object

Edit: Rust seems to do it that way and it allows cool stuff like saying Set<Key> = Map<Key, ()> (https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts), but getting that to work seems a lot more involved

@SirOlaf SirOlaf closed this Oct 20, 2022
@arnetheduck
Copy link
Contributor

typeof(G[void]().x) should still work in the above example - it's useful in generic code to not have to introduce a special case for void, often

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

That never worked because as I said it makes the fields disappear completely https://play.nim-lang.org/#ix=4dGQ

Edit: Specifically here https://github.com/nim-lang/Nim/blob/devel/compiler/semtypinst.nim#L208

@Araq
Copy link
Member

Araq commented Oct 20, 2022

Edit: Rust seems to do it that way and it allows cool stuff like saying Set = Map<Key, ()>

Nim had that before Rust, see e.g. CritbitTree[void].

@arnetheduck
Copy link
Contributor

That never worked

too bad - makes for a good feature request :)

@SirOlaf SirOlaf mentioned this pull request Oct 20, 2022
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.

void type allowed in type definitions, use leads to compiler error
3 participants