Skip to content
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 20848: format should work with immutable(void)[] #7556

Merged
merged 1 commit into from
Jan 28, 2021

Conversation

quickfur
Copy link
Member

The bug is that if T == immutable(void)[], then const(T) does not collapse to const(void[]), but is actually const(immutable(void)[]). So a strict type equality check will fail.

However, const(T) is implicitly convertible to const(void[]), which serves our purpose just as well. So just use that check instead.

@quickfur quickfur requested a review from andralex as a code owner July 13, 2020 21:47
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @quickfur!

Bugzilla references

Auto-close Bugzilla Severity Description
20848 normal Bug in formatValueImpl

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7556"

std/format.d Outdated
@@ -3213,7 +3213,7 @@ if (is(StaticArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
private void formatValueImpl(Writer, T, Char)(auto ref Writer w, T obj, scope const ref FormatSpec!Char f)
if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
{
static if (is(const(ArrayTypeOf!T) == const(void[])))
static if (is(const(ArrayTypeOf!T) : const(void[])))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this true for any non-shared array T?

std/format.d Outdated
@@ -3213,7 +3213,7 @@ if (is(StaticArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
private void formatValueImpl(Writer, T, Char)(auto ref Writer w, T obj, scope const ref FormatSpec!Char f)
if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
{
static if (is(const(ArrayTypeOf!T) == const(void[])))
static if (is(const(ArrayTypeOf!T) : const(void[])))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static if (is(const(ArrayTypeOf!T) : const(void[])))
static if (is(immutable(ArrayTypeOf!T) == immutable(void[])))

@Geod24
Copy link
Member

Geod24 commented Aug 3, 2020

CI is not happy

@quickfur
Copy link
Member Author

OK, this must be some kind of pathological compiler bug. The failing unittest stops failing when I comment out the newly-added unittest, but the bugfix itself appears to have no effect on the error. Swapping the bugfix for the original code appears to have no effect on this, but the act of adding this particular unittest triggers the failure.

WTH is going on here?!

@quickfur
Copy link
Member Author

Oh actually, come to think of it, now I remember something about the compiler caching the stringification of a delegate, but there's a bug where certain overloads share the same cache entry, so depending on which symbol was interrogated first, the .stringof will differ.

Argh, yes, it's this bug (again, sigh): https://issues.dlang.org/show_bug.cgi?id=18269

@quickfur
Copy link
Member Author

And this same bug is blocking another Phobos PR: #5797

It's been 3 years, and still, no progress. :-(

@quickfur
Copy link
Member Author

I am very tempted to just disable the offending unittest. Unittests shouldn't depend on the exact string format the compiler will generate for a particular type.

The bug is that if `T == immutable(void)[]`, then `const(T)` does not
collapse to `const(void[])`, but is actually `const(immutable(void)[])`.
So a strict type equality check will fail.

However, `const(T)` *is* implicitly convertible to `const(void[])`,
which serves our purpose just as well. So just use that check instead.
@atilaneves
Copy link
Contributor

I am very tempted to just disable the offending unittest. Unittests shouldn't depend on the exact string format the compiler will generate for a particular type.

I agree that brittle unit tests like that aren't useful. It'd be better to replace it though with a better test.

@berni44
Copy link
Contributor

berni44 commented Jan 28, 2021

@RazvanN7 With #7771, fixing the problem with the unittest IMHO this can be merged now.

@RazvanN7
Copy link
Collaborator

Thanks @berni44 !

@dlang-bot dlang-bot merged commit 50c00a0 into dlang:master Jan 28, 2021
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.

8 participants