-
-
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 Issue 8747 - isAssignable!(int, const(int)) is false #832
Conversation
|
To improve unittest is not so bad, but don't squash unrelated changes into one commit. |
|
Changing |
| @@ -2957,8 +2959,7 @@ template isAssignable(Lhs, Rhs) | |||
| { | |||
| enum bool isAssignable = is(typeof({ | |||
| Lhs l = void; | |||
| Rhs r = void; | |||
| l = r; | |||
| void f(Rhs r) { l = r; } | |||
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 is this different from the original code?
* improve `isAssignable` unittests * add immutable(S) test to `hasElaborateCopyConstructor` * add const(S) test to `hasElaborateAssign`
Original code: const(int) ci = void;
int i = ci; // Causes `Error: void initializer has no value` on previous lineBy the way, this Lhs l = void;
Rhs r = Rhs.init;
l = r;But it looks more like a compiler bug: struct S { @disable this(); @disable this(this); }
void main()
{
S s1 = S.init; // no errors
s1 = S.init; // still no errors
S s2 = s1; // Error: struct S is not copyable because it is annotated with @disable
}So, is it a bug?
It's difficult to distinguish so I decided to separate all not directly related unittest changes. E.g. in S s = void;
return &s.__postblit;and it may eventually become rejected with void initializer has no value error. So this is related to the source of issue 8747 but not to the issue itself. |
|
What about my |
That looks like a normal behavior to me, and would be what I expect. S's struct S { @disable this(); @disable this(this); @disable bool opAssign(this);}
void main()
{
S s1 = S.init; // no errors
s1 = S.init; // THIS TIME Error here
S s2 = s1;
}
[EDIT] Removed Section Related: I was creating a pull to fix that "assignmentq" typo. Thanks for getting it. |
|
If you are writting a function to do the test (good idea, IMO, btw), then why not just limit the test to the availability of the function itself (as opposed to a block containing a function)? template isAssignable(T, U)
{
enum bool isAssignable =
is(typeof((ref T t, ref U u) => {t = u;}));
}
This form is concise and verbose, and should avoid any traps related to anything disabled. |
|
I think the root cause of bug 8747 is a compiler bug. The original code of |
But, the change for In any case, your commit separation looks good to me. Let's merge! |
Fix Issue 8747 - isAssignable!(int, const(int)) is false
|
Merged. |
|
Oh, one more thing. Shouldn't we default the second argument? |
Wow, it sounds good. There is undocumented template |
isAssignableunittest