-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
restrict usage of typedesc, improve error messages #11959
Conversation
@zah I am requesting your review of this PR, since you were involved in designing I am also interested in your perspective because you are most likely to know some use cases that were not covered in the test cases that I broke with this PR. |
I don't know how if I can say this PR would fix #11152. This PR disallows/discourages the pattern in the named PR in such a way that the problem would not occur. In general this PR make the uglyness of typedesc bubble up. But on the upside at least you get a grasp of what typedesc is actually doing in the compiler. |
Here's an example that "could" be a https://github.com/status-im/nim-stint/blob/master/stint/private/datatypes.nim#L133 reasoning about types is generally useful when dealing with generics etc - the less "friction" |
@arnetheduck I am sorry I have no Idea what you are talking about. What do you mean by "types where first-class citizens"? I don't know what you mean with "could" in quotes. And I don't see how the example you give would be any better if it would be a proc. So what is your suggestion? |
|
I did not know either, but I agree that a proc taking a typedesc is generic, in the same way a proc taking a static parameter is: it cannot be compiled until it is specialized to know what the type (resp. the static value) is |
I find this change completely pointless. Crippling the syntax of type parameters because you personally don't like them and asking everyone to spend hours in non-productive code editing is a pretty good way to alienate the existing user base of Nim. I would suggest spending some time in going through our codebase to see how the required rework will make you feel. Furthermore, this is yet another change that hasn't been reflected in the manual. Going through the required changes in the manual is a good way to see if a suggested change is conceptual simplification or whether it must be described as an unusual special case. At the moment, the manual describes |
c7e871e
to
6757b75
Compare
fixes #13225 |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
Restrict the usage of
typedesc
for parameters only.code like this won't compile anymore:
This PR will also introduce a warning that encourages to rewrite code like
proc foo(T: typedesc): T
asproc foo[T](t: typedesc[T]): T
. This way of passing type parameters to procedures has been proven to be the most reliable way to do it.