-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Fix std.traits.hasElaborateAssign
#954
Fix std.traits.hasElaborateAssign
#954
Conversation
|
@9rnsr, is there any way to determine if there is a user defined |
|
|
Related compiler bug: http://d.puremagic.com/issues/show_bug.cgi?id=9154 |
|
Shouldn't It fits with the scheme of:
|
I'd say no simply because they're not built into the language like |
| int i = rvalueOf!int; // error, no actual value is returned | ||
| --- | ||
| */ | ||
| @property T rvalueOf(T)() inout; |
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.
inout-qualified module level function should not be accepted. I think it is a compiler bug.
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.
So how should I workaround this:
T f(T)() { assert(0); } // line 1
void g() {
f!(inout int)();
}Output:
main.d(1): Error: inout on return means inout must be on a parameter as well for T()
main.d(4): Error: template instance main.f!(inout(int)) error instantiating
?
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.
In current, most better workaround I can suggest is:
https://github.com/D-Programming-Language/phobos/pull/842/files#L1R143
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.
Looks good for functions, but isn't the fact that @property T defaultInit(inout int = 0); is a getter instead of being a setter is another compiler bug?
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.
Not necessarily. It takes an argument, so it can be used as a setter (and setters can return like you'd expect from opAssign), but the fact that it has a default argument means that you could use it as a getter. I could see an argument though that it doesn't really make sense for it be a getter, since it presumably does some setting as it does take an argument (default or not). So, I don't know what the correct answer is. It doesn't surprise me though if the compiler lets it be used as a getter.
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.
In current, compiler does not treat @property function so much specially than other normal functions in its semantic analysis.
A @property attribute for a function declaration just means that provides a syntactic sugar for the usage of the function.
In other words, compiler does not recognize that a @property function is getter or setter.
It depends on how the function is used.
// Compiler recognizes just foo is annotated with `@property`, and has one default argument.
// Compiler *does not* recognize that foo is a getter or setter.
@property int foo(int n = 0) { return n; }
foo = 1; // foo is used as a setter property. @property attribute for foo allows this *syntax*.
int n = foo; // foo is used as a getter property. @property attribute for foo allows this *syntax*.
foo(1); // foo is used as a normal function.
// compiler should be reject this syntax as a use case of foo. (But this is not implemented yet)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.
Hm, I found a good explanation about that.
A @property attribute just affects to the function name, not affects to the function declaration itself.
And, if the name annotated with @property is used like a variable, it is allowed. If the name is used like a function, it is disallowed.
Practically we might need some additional rules, but it is a principle explanation, in my opinion.
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.
Thanks for the explanation. And yes, it will be really good to have this in docs, if you will be kind enough and will manage to find enough time.
|
Rebased (just in the case someone cares). |
|
Am I understanding correct that there is no "implicitly convertible to lvalue" objects any more? |
I'm not sure what you mean. I'm not aware of anything ever implicitly converting to an lvalue. However, struct literals are no longer lvalues. Perhaps thats' what you're referring to? |
|
Yes, you are not aware of the topic. template isImplicitlyConvertableToLvalue(alias a) if(!is(a))
{ enum isImplicitlyConvertableToLvalue = __traits(compiles, (ref x) { } (a)); } |
|
Unfortunately doesn't merge any longer. Has the confusion been cleared up in the meantime, and could you please rebase the pull request? I'd hate to see all your work on static array handling go to waste. |
I don't think so.
Done.
Some people hate black people, some people hate Russians, Phobos maintainers hate static arrays. |
This is way out of line. |
|
Yah, I meant to reply to that. This kind of drama and hyperbole may seem cool at the originating end but at the receiving end is just inappropriate, so at best we should refrain from it. Regarding the matter at hand, @denis-sh you'd help a lot if you made collaboration just a little easier. Thanks! |
|
Rebased extracting everything but fixes and small refactoring to other pulls (see description). |
|
The third commit (the "money" commit) looks good to me. It fixes yet another issue on a trait that forgets that static arrays can have complex behavior. We needs these fixes merged in sooner rather than later. The other two commits feels only like code churn though: I'd feel more comfortable if you changed every instance of |
|
The change in Other two changes (replacing to |
|
I see, there is really no consensus, it was just IMO, sorry. Removed But replacing of So there is the only commit waiting here... |
|
LGTM. Please wait auto tester green. |
|
LGTM, waiting for the tester to go green. |
Fix `std.traits.hasElaborateAssign`
|
Is there a bug report for this? |
No. |
Ok, but in the future do make a bug report if one does not exist, and in the commit message add |
|
(for the fix to show up in the changelog) |
Fix
hasElaborateAssignfor static arrays.Other changes are extracted to pulls #1260 and #1261.
http://d.puremagic.com/issues/show_bug.cgi?id=9956