-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Issue 17269: formattedWrite of struct with Nullable value fails #5797
Conversation
Thanks for your pull request and interest in making D better, @CromFr! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#5797" |
@@ -3251,6 +3251,29 @@ if (is(AssocArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) | |||
|
|||
@safe unittest | |||
{ | |||
// Bug #17269. Behavior similar to `struct A { Nullable!string B; }` |
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.
Why not use a struct with Nullable!string
?
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.
If I use a Nullable!string, it causes an assert failure on another unittest block
expected = `void delegate() @system`, result = `void delegate()`
I don't really understand why, so I wrote a custom struct to:
- Show the
alias this
and the implicit conversion problem - Do not depend on Nullable if it is changed in the future
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.
Huh? Nullable!string
works without your PR: https://run.dlang.io/is/Jjzpvo
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.
Could you provide a test case where it fails and maybe open another bug report?
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.
you need to put the Nullable!string inside a struct to see it fail:
struct NullableStr {
Nullable!string value;
}
NullableStr f;
format("%s", f).writeln;
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.
This should've been fixed by #2587... Looks like this is a case that was missed by the tests. I don't have time to investigate at the moment, but I don't think this is the correct solution so please don't pull this yet.
Urgh, it's all Looks like |
fyi the first fix I thought of was to modify |
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.
Looks reasonable to me as well, though as noted Nullable!string
already works.
Reworded the commit message, s.t. the dlang bot recognizes it and it can be auto-closed and part of the changelog (and also rebased to upstream/master). |
I added the initial example of as an additional
|
I encountered the same unittest error when initially trying to fix formattedWrite Since it didn't make much sense to me, I changed the test to use a custom struct that has the same problem as Nullable!string and the unittest error disappeared, so I concluded that it was because of a weird import conflict or something like that, without much more investigations |
Rebased. Hopefully it will go through this time. |
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.
While it would be nice to track down the exact cause of the error caused by testing Nullable
directly, I don't think that should hold up this PR. LGTM.
Hmph. Seems that avoiding Update: Nevermind, it is the |
I think there's a compiler bug associated with this. Moving the offending unittest above the unittest that imports |
I think dlang-bot should add a message when the PR becomes un-mergeable. I didn't receive any notification on this :/ |
@CromFr BTW, I already rebased your pull, you may want to fetch from dlang/phobos to update your local branch if you're planning to adding more commits. |
Managed to reduce the bug to a minimal(-ish) case: https://issues.dlang.org/show_bug.cgi?id=18269 A truly bizarre compiler bug where unrelated declarations can affect the type of a delegate! |
That's a nasty one. Thanks for the reduction @quickfur. Anyone have a suggestion for how to proceed? I don't want this to fall by the wayside because of an obscure compiler bug. |
One way to deal with this, if it's deemed urgent to merge this PR sooner rather than later, is to |
How about moving the unittest to a different module? |
On Tue, Jan 23, 2018 at 07:11:46PM +0000, Sebastian Wilzbach wrote:
How about moving the unittest to a different module?
[...]
I suppose we could try that too. No idea whether it will work, though.
The compiler bug seems highly sensitive and fragile to small changes.
I'd like to dig to the bottom of it sometime, but it's deep in the
complicated and messy IFTI code, and I'm not sure I'll be able to figure
it out!
…--T
|
In the meantime, perhaps we could change the order of the offending unittests so as the bypass the compiler bug? I'm not sure when the compiler bug will be fixed; it's a pretty tricky one involving an ambiguity in the global stringtable. |
Yeah that's why I thought that putting it in a separate module will help as it reduces the chances of someone accidentally running into this in the near future again. |
Unfortunately, the problem is cross-module. The original problem was caused by the import of |
@CromFr Please rebase this and we will get it in. |
Should be good now :) |
@RazvanN7 circleci seems not to respond... Is there anything, that can be done? |
Superweird. I can't even access the details page. |
@berni44 I just restarted it. Let's hope it doesn't hang again. |
The bug was caused by formatElement implicitly converting Nullable!string to string, that resulted in an error when the Nullable was null.
New behavior is to use the toString method when available, instead of implicitly converting the value.