-
-
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
nonpure enum can hijack pure enum; instead should give Error: ambiguous identifier
; pure and nonpure should both mean the same thing; pure should be deprecated
#8850
Comments
No, it works as expected and documented. It's true that I want to merge pure and non-pure enums though, eventually. |
These scenarios can always be conjectured and are not convincing. If they were, we wouldn't embrace overloading to begin with. |
That isn't a very obscure scenario though.. I'd imagine a lot of people using enums this way, and any module that happens to use the same value for an enum would break that.. I'm still for bringing pure enums back, can't really see a reason to remove them.. |
Once we merged pure with non-pure enums completely the scenario is gone. And yes, |
with overloading you'd get compile error: ambiguous call:
I don't think this is contrived, I just gave a simple example. This arises in many other scenarios, that silently give different results instead of compile error: echo red
foo(red) # where `foo` is generic (and itself calls thing that accept either form of `red`)
$red
int(red)
type(red).name
type(red).sizeof
...
great, then let's keep this issue open to track this :) ; so looks like we agree on P1,P2,P3 before merging pure and impure enum we need to resolve how they work in other aspects; see |
@Araq confirmed on gitter https://gitter.im/nim-lang/Nim?at=5bafb1e019b139275a1de6ac that (please correct me if I mis-understood) |
I can confirm that's what will be done. |
EDIT: i read somewhere (sorry, forgot whether it was in IRC or forum or github) that pure is now a no-op (ie implicit), however that's still not the case in latest devel (b2a5195); pure and non pure still have different semantics eg1:
eg2: |
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions. |
ccing ppl from related discussion
/cc @Araq @dom96 @PMunch @mratsim
silent hijacking is bad.
now that 2f7b979 was committed, I think we should do the following (see rationale below)
Error: ambiguous identifier
instead of hijacking it; see example belowsee #8066 for related discussion
rationale:
imagine following scenario:
later thirdpartylib2.nim gets udpated as follows:
Now
call_c_library(int(red))
callscall_c_library(2)
this can lead to nasty bugs under the nose of application writer.
Instead the only sane way here is to give compile error:
Error: ambiguous identifier
(P1)Which leads to P2 and P3 since now pure and impure would mean the same thing, modulo nit below (which shouldn't be relevant enough to warrant having 2 concepts)
P2a: things to resolve before merging pure and impure
int.red
, pure doesn't unless the symbol is qualified:X.red.int
orint(red)
; if we are to do P2 and P3, I'm fine with either rule (allow or disallow UFCS without qualification (when unambigious))I suggest following pure's rules in all cases
note
that seems in line with https://irclogs.nim-lang.org/22-10-2017.html#13:54:23
links
Pure really removed for enums? - Nim forum
The text was updated successfully, but these errors were encountered: