-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Feature: Member of Operator #16161
Feature: Member of Operator #16161
Conversation
…ng set for delayed rewrite
Thanks for your pull request and interest in making D better, @rikkimax! 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. 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#16161" |
96bc04b
to
b5c58c3
Compare
b5c58c3
to
cae85fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much of the test case needs to actually be runnable? I suspect that most of it could be made compilable.
} | ||
|
||
static assert(!__traits(compiles, { const fail = :max; })); | ||
static assert(!__traits(compiles, { Context fail = :max.min; })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silly question: why does this fail? this breaks my metal model of :
as shorthand for typeof(lhs)
(or typeof(return)
as appropriate).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like it might be more useful to have a token which represents the expected type, so you can call its constructor:
fun(_(5), _.some_member)
.
assert(0); | ||
} | ||
|
||
static assert(!__traits(compiles, { const fail = :max; })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also check for auto
, immutable
, static
, shared
, __gshared
(any other type redundant modifier I'm forgetting?).
Also should check for initialisation at
- module scope,
- class/struct scope
- (other scopes I may be forgetting?)
@rikkimax What are your plans with regards to this feature? This looks like something that would require a DIP. |
The plan is to basically let this bitrot. It exists to prove that it can be done without introducing a lot of complexity in the compiler. |
Ok to close? There is no practical difference in keeping this open, apart from constantly appearing in the PR queue. |
An alias can do that, too:
|
Is there a drawback syntactically for using Otherwise, I love this idea, and have loved it since I used it in Swift. |
Changelog added. |
https://dlang.org/spec/arrays.html#ArrayInitializer You need the identifier to proceed the It only applies to the first term of an expression, so as far as I know there are no downsides. |
This is a new feature, which I'm calling member of operator.
It is based upon Neat's Identifier Type.
In certain statements and expressions, there is a context, when seen with the operator it gets the member and rewrites the AST to use that instead.
Supports function calls, variable declarations, case statements for switch statements, and return expressions.
Dot expressions after it has not been implemented, although that should be done.
Why did I implement this? To prove that even I with limited knowledge can do it. It isn't a complex feature. It was less than 10 hours work with a bit of help from @dkorpel to point in the right direction!
My motivation is to make it be the mechanism to describe sum-type tags without a value type. It also applies to value type exceptions aka zero cost, to replace zero size struct support.
Test case which has all the examples in it:
master...rikkimax:dmd:member-of-property#diff-476a4c5f24136a55eb521b2a39faad10ce01dc3075af4f4ceceb82acd22242c3
But the difficult one that is worth copying
Enum varF2 = identity(:Middle);
.