Change regarding invariant-noncompilant .init values#2418
Change regarding invariant-noncompilant .init values#2418dukc wants to merge 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @dukc! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
If you disagree, see #2410 instead |
|
Note that the invariant is not checked on access to edit: On the other hand, opening yourself to crashing bugs on null pointer access of course, which So I don't disagree per se; I'm just saying this entails a compiler change. edit: More interesting notes: if a struct with invalid |
|
Strictly speaking, the invariant is called after a constructor is completed, before and after public functions are called and before the destructor is called. It would be far better to say something like "Default initialization does not trigger the invariant as no functions are called during default initialization." |
|
The problem is the asymmetry: the invariant is not called on |
|
As FeepingCreature said, non-invariantcompliant only make sense when you are not going to change the value at all, because a change would trigger the invariant first. But even that does not make sense when there is the destructor, which inevitably also triggers the invariant. Either making But I just realised my option here would mean code breakage. The disadvantage of the other option is that it closes the future possibility of removing the check before a function call, unless we allow doing work on EDIT: another option is deprectating instantiating |
Honestly, I don't see any problem with that. If you understand how an invariant works, then you can code accordingly. The key issue as far as updating the spec goes is ensuring that it's clear. Also, checking the invariant after default initialization is kind of silly given that it's always going to be the same value, and if there were any problem with its invariant, then it would fail as soon as you called any functions on it. And honestly, from a strictly pedantic point of view, having an invariant that fails for Regardless, if you want to argue about why the current behavior should be changed and write a DIP about it, then that's fine, and we may very well end up with something better as a result, but that's a completely separate issue from updating the spec. If the spec isn't clear enough about how the language currently works, then we can update it to clarify it, but a DIP is required if you actually want to change the semantics of the language. |
|
I disagree fundamentally with both your points, but this is probably not the place, yeah. Are you on IRC or Discord? This might be easier to work out in conversation. That said, I'll probably just work around it with union. edit: "Deprecating inits with invalid values" is in effect equivalent to either "deprecating struct invariants", or "deprecating structs for domain data, period." |
|
I said: deprecating instantiating invalid |
|
Closed as I promised. |
See https://forum.dlang.org/post/ohohfaisyaregskmkzme@forum.dlang.org