Implementation of Properties.#12097
Implementation of Properties.#1209712345swordy wants to merge 13 commits intodlang:masterfrom 12345swordy:Properties
Conversation
|
After a few years of experience with other languages I've come to appreciate the dedicated syntax that some of them provide (e.g. C#, Dart, JavaScript), as opposed to D's bare-bones approach.
This could be done via a single, or two separate DIPs. |
|
On Mon, Jan 04, 2021 at 09:12:37AM -0800, Petar Kirov wrote:
2. Add syntax sugar on top. The expression-bodied members syntax would be a very nice win.
please note:
#11833
if you wanna help by writing the spec PR that'd probably help keep that
after the preview.
|
src/dmd/expressionsem.d
Outdated
| * the rewritten expression if the procedure succeeds, an `ErrorExp` if the | ||
| * and error is encountered, or `null` if `e.e1` is not a `@property` function. | ||
| */ | ||
| Expression SemanticProp(BinAssignExp e, Scope* sc) |
There was a problem hiding this comment.
Isn't this called binSemanticProp?
There was a problem hiding this comment.
It used to be called that. It was initially to be implemented for binary operators only, which I plan to expand father than that. That may change in future.
|
Nice, but why those?
|
That is part of the design I have in mind. It meant to be used as a variable, with the key difference is that you can't obtain the address of it directly nor can you pass it to a ref parameter of a function. All write and read access of the private variable outside the module must go through the functions themselves. No exceptions. I will explain this further in detail when I write up the dip of this. Edit: This is my major influence. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties |
|
@12345swordy Can you please link the original PR so that reviewers can easily keep track of the discussions? |
|
|
NM |
|
OK, after much discussion on discord, I decided to remove the "disallow functions that is mark property from returning ref" restriction. |
|
Finished 80% implementation of binary operators for properties, the other 20% involves an edge case that I am not sure that it should compile. |
|
Thanks for your pull request and interest in making D better, @12345swordy! 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 references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12097" |
|
@RazvanN7 are you available at slacks or at discord? I need assistance on finishing this. |
|
It is done for review. Need to rebase it, now. |
…in the case where 't +=4' where T is the type itself that has alias this a property function.
…ncorrectly." This reverts commit 1e8514e.
| testTInt(); | ||
| testTString(); | ||
| testFreeFunctions(); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Add a newline to conform with POSIX 3.206 .
| testSideEffectsInt(); | ||
|
|
||
| testSideEffectsString(); | ||
| } No newline at end of file |
|
@12345swordy Sorry for the late reply. Yes, I am available on slack. Whatever questions you may have, feel free to ask. |
I have rebase @JinShil PR on this and added some to the test.
TODO:
cc @thewilsonator need a "need DIP" and "Spec PR" red tag for this.