Skip to content

Fix Issue 7879 - format of const class with non const toString()#6207

Merged
wilzbach merged 2 commits intodlang:masterfrom
JackStouffer:issue18486
Feb 28, 2018
Merged

Fix Issue 7879 - format of const class with non const toString()#6207
wilzbach merged 2 commits intodlang:masterfrom
JackStouffer:issue18486

Conversation

@JackStouffer
Copy link
Contributor

So trying to make Object.toString const was a nightmare, so I added in this work-around to at least allow the code to compile.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JackStouffer!

Bugzilla references

Auto-close Bugzilla Severity Description
7879 normal format of class with not const toString()

@JackStouffer JackStouffer changed the title Fix Issue 7879 - format of class with not const toString() Fix Issue 7879 - format of class with non const toString() Feb 21, 2018
@JackStouffer JackStouffer changed the title Fix Issue 7879 - format of class with non const toString() Fix Issue 7879 - format of const class with non const toString() Feb 22, 2018
@JackStouffer
Copy link
Contributor Author

Changed code to match std.format's existing behavior for class formatting

@wilzbach
Copy link
Contributor

So trying to make Object.toString const was a nightmare

Yeah, though we should really move things out of object.d.
A quick selection:

{
class F
{
override string toString() const @safe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW we can't use inout here: https://issues.dlang.org/show_bug.cgi?id=18500

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice workaround!
Maybe we can wait until #6209 is pulled, s.t. we can remove the magic numbers a bit?

else
{
static if (hasToString!(T, Char) > 1 || (!isInputRange!T && !is(BuiltinTypeOf!T)))
static if ((is(T == immutable) || is(T == const) || is(T == shared)) && hasToString!(T, Char) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could use == none here.
See: #6209

put(w, typeid(Unqual!T).name);
put(w, ')');
}
else static if (hasToString!(T, Char) > 1 || !isInputRange!T && !is(BuiltinTypeOf!T))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #6209: !overload.among(none, hasSomeToString)

@JackStouffer
Copy link
Contributor Author

Moving ahead with this to shorten the queue.

@JackStouffer
Copy link
Contributor Author

@wilzbach Can I get a manual merge?

@wilzbach wilzbach merged commit 93dc74b into dlang:master Feb 28, 2018
@JackStouffer JackStouffer deleted the issue18486 branch February 28, 2018 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments