-
-
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
format() returns the correct type #3528
format() returns the correct type #3528
Conversation
|
Seems sane but might break existing code. Let's wait what others have to say |
|
This makes sense to me. |
|
@DmitryOlshansky Out of curiosity, can you come up with a scenario where this breaks code? |
|
I guess using |
Yeah. This and maniacs using explicit types everywhere such as string for return and wstring for fmt. If it's going to hit simebody then it must be windows folks, being the most prominent use case for UTF-16. |
|
Please squash the commits to one commit and it should be good to go |
|
May need to whitelist @vladdeSV for auto-tester - @MartinNowak @braddr ? |
|
Squashed the two commits. It should be good to go? |
|
One thing I think should be change is to replace my template name Thoughts? |
|
|
I also feel |
Change type from C to S
|
I changed the |
|
I changed However, I do not see a reason to have |
|
This currently passes all tests, but I made some changes in Also, I'd say that c3e86ff should simply be an alias, if not to replace the function calls in the code to |
|
One thing I really don't like is how it uses String as template parameter. Ideally it should accept const(Char)[] and produce mutable Char[]. Then if format is
Using cast like that is very bad idea it just reinterprets the array, you should use Exactly the kind of thing to watch out for. We are early in release cycle so it might be fine to break a few cases like that. |
| @@ -27,7 +27,7 @@ import std.range.primitives; | |||
| import std.traits; | |||
| import std.typetuple; | |||
|
|
|||
| private string convFormat(Char, Args...)(in Char[] fmt, Args args) | |||
| private S convFormat(S, Args...)(in S fmt, Args args) if (isSomeString!S) | |||
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.
Do we even call it internally anywhere? It's private should be easy to just drop it...
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.
Yes, at a few places.
Line 1404, 1775, 3931 ...
I wonder if it would be simpler to just replace that with std.format.format
I see. Yes I agree, I'll do some testing.
My bad, I did do |
Replace std.conv.convFormat() with alias to std.format.format()
|
@DmitryOlshansky I tried, I failed. I don't know how to make the function as you described. I tried to change |
|
@vladdeSV Did you mark the function |
|
ping @vladdeSV |
|
@quickfur Sorry, been busy past days. I'll try again :) |
|
Pong @quickfur This means I need to make And a question: I built phobos with |
|
Most of Phobos is template code, so just building it may not necessarily reveal all compilation problems. Try Usually that takes too long, though. I usually just run unittests for a specific module manually by doing |
|
Changing the function to be pure needs many changes in the code. For instance, I needed to change some things in I don't really want to fiddle around in all of these files and just put pure on things I do not know anything about. Unless I get some help I'd rather make it return a correct string type instead of char type. But having it return correct type of char array is something I feel would be very nice to have. Piong @quickfur |
It's a a lot of work. Let's keep this simple and move with just changing the return type. |
|
@DmitryOlshansky Should I revert my latest commit? |
|
@vladdeSV no, rather squash all of them to one |
|
@DmitryOlshansky Just to be clear: I should not keep the latest commit that fails the build? |
|
@vladdeSV - kill pure, keep Char[], and make it one commit. |
Change type from C to S Fix error in conv.d Added isSomeString Changed unittests assert message is converted to string Change S to Char[] Replace std.conv.convFormat() with alias to std.format.format() Revert S to Char[] Change back to Char[] Remove pure
|
@DmitryOlshansky I've squashed them to one, however just as before it does not build. |
|
Well previously it was string aka immutable(char)[] |
…eSV/phobos into format-return-correct-type Conflicts: std/format.d
This causes problems when I think the current best solution is to go back to my first suggestion. I can't make it return immutable (Char)[], but I can make it return a string of the correct type. Any other suggestions? |
| { | ||
| import std.format : formattedWrite, FormatException; | ||
| import std.array : appender; | ||
| auto w = appender!string(); | ||
| auto w = appender!(Char[]); |
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.
Char[] -- > immutable(Char)[]
|
I pointed specific places. |
|
Thank you @DmitryOlshansky ! |
|
Auto-merge toggled on |
format() returns the correct type
Changed
format()to return the same type of string that was inputted.For instance, formatting a dstring returns a dstring and not string.