[trivial] std.conv: Don't allow to!T() in constraint#4898
[trivial] std.conv: Don't allow to!T() in constraint#4898schveiguy merged 4 commits intodlang:masterfrom
Conversation
Also avoid highlighting 'to' unnecessarily.
isStaticArray!T already checks !isAggregateType!T.
|
std/conv.d
Outdated
| /// | ||
| T to(A...)(A args) | ||
| if (!isRawStaticArray!A) | ||
| if (A.length > 0 && !isStaticArray!(A[0])) |
There was a problem hiding this comment.
Ideally we should have 2 overloads instead of just using args here, I can do that after this pull is merged.
| enum isRawStaticArray = | ||
| A.length == 0 && | ||
| isStaticArray!T && | ||
| !is(T == class) && |
There was a problem hiding this comment.
These static tests are for alias <member that's a static array> this, can they really be suppressed ?
There was a problem hiding this comment.
Yes, please see the full commit message.
std/conv.d
Outdated
| * literals are not handled. Neither the prefixes that indicate the base, nor the | ||
| * horizontal bar used _to separate groups of digits are recognized. This also | ||
| * applies to the suffixes that indicate the type. | ||
| * applies _to the suffixes that indicate the type. |
There was a problem hiding this comment.
don't merge two fixes. the to -> _to is another issue. If your PR gets merged for the code and reverted because of regression than the fix for the DDOC will also be lost.
There was a problem hiding this comment.
Ideally, yes. But I think this is what most people do for very minor changes, otherwise we'd get tons of PRs.
There was a problem hiding this comment.
You hit a wall here. Don't merge two things in one PR. End of story. Waiting for you to amend.
Open another PR for the ddoc.
There was a problem hiding this comment.
we'd get tons of PRs.
That's not a problem, annotate it with [TRIVIAL, DDOC] and it'll be merged quickly.
There was a problem hiding this comment.
Removed doc changes.
|
@bbasile Merge please? |
std/conv.d
Outdated
| { | ||
| T to(A...)(A args) | ||
| if (!isRawStaticArray!A) | ||
| if (A.length > 0 && !isStaticArray!(A[0])) |
There was a problem hiding this comment.
I believe the previous constraint is equivalent to this instead:
if(A.length > 0 || !isStaticArray!(A[0]))The calls it allows vs. your constraint, I'm not sure are valid. But this is a difference.
There was a problem hiding this comment.
Boy, that's not a very good constraint :)
This is better
if(A.length != 1 || !isStaticArray!(A[0]))|
LGTM, just fix the constraint, and I will merge. |
schveiguy
left a comment
There was a problem hiding this comment.
Nevermind, I forgot I can just fix it myself :)
|
Auto-merge toggled on |
|
@schveiguy: You have undone the fix for the issue.
I think we can use specialization to achieve what you want neatly: Note: my original code was actually correct because for more than one argument, the only options are for the first argument to pass |
|
I thought the issue was that the internal isRawStaticArray appears in the error message? |
|
to!string() shouldn't compile, and I don't think it did with the original code, right? So why change the constraint? |
|
You're right it doesn't successfully compile, but the constraint should prevent internal errors with |
|
BTW Thanks for reviewing, the original issue is much better after this merge ;-) |
Also document
totemplate functions within parenttotemplate.