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 19226 - std.typecons.Nullable(T, T nullValue) doesn't fully handle non-self-equal nullValue #6693

Merged
merged 1 commit into from
May 9, 2019

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Sep 5, 2018

Nullable(T, T nullValue) special-cases floating point numbers but this doesn't account for all types where nullValue != nullValue. For instance:

https://run.dlang.io/is/hiLncI

struct S
{
    float f;
}

void main()
{
    import std.typecons : Nullable;

    alias N = Nullable!(S, S.init);
    assert(N(S.init).isNull); // Fails!
}

@dlang-bot
Copy link
Contributor

dlang-bot commented Sep 5, 2018

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
19226 normal std.typecons.Nullable(T, T nullValue) doesn't fully handle non-self-equal nullValue

Testing this PR locally

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

dub fetch digger
dub run digger -- build "master + phobos#6693"

@schveiguy
Copy link
Member

Is this different/related to #6583?

@schveiguy
Copy link
Member

Oh nevermind, this isn't about opEquals.

@n8sh
Copy link
Member Author

n8sh commented Sep 5, 2018

It is related though since opEquals requires we know how to properly check isNull.

@n8sh
Copy link
Member Author

n8sh commented Sep 5, 2018

Opened bug report https://issues.dlang.org/show_bug.cgi?id=19227 S.init is S.init failing for struct with float member.

@schveiguy
Copy link
Member

Is there a codegen bug on Linux 32-bit? Seems odd that the test case would only fail on that platform.

@n8sh
Copy link
Member Author

n8sh commented Sep 5, 2018

It seems like this must be a bug.

std/typecons.d Outdated Show resolved Hide resolved
@@ -3476,7 +3476,7 @@ Returns:
}
//Need to use 'is' if T is a float type
//because NaN != NaN
else static if (isFloatingPoint!T)
else static if (__traits(isFloating, T) || __traits(compiles, { static assert(!(nullValue == nullValue)); }))
Copy link
Member Author

Choose a reason for hiding this comment

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

Q: Why is there the seemingly-extraneous __traits(isFloating, T)?
A: So this patch doesn't change the behavior of Nullable!(double, -0.0).

@n8sh n8sh force-pushed the issue-19226 branch 2 times, most recently from f1643ea to 0ebd89f Compare December 17, 2018 01:49
@thewilsonator thewilsonator added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Jan 4, 2019
@n8sh
Copy link
Member Author

n8sh commented Jan 5, 2019

The wrong code generation on 32-bit linux was still happening last I checked so I expect this not to go through.

@12345swordy
Copy link

3 days have been passed already.

@wilzbach wilzbach removed the 72h no objection -> merge The PR will be merged if there are no objections raised. label Jan 11, 2019
@wilzbach
Copy link
Member

The wrong code generation on 32-bit linux was still happening last I checked so I expect this not to go through.

Yup, it's still there.

@n8sh
Copy link
Member Author

n8sh commented Jan 19, 2019

I've been unable to replicate the Linux_32 / Linux_64_32 problem locally so far so I'm unable to tell what the problem is or make a useful bug report.

@n8sh
Copy link
Member Author

n8sh commented Feb 23, 2019

I am changing the test case for this PR. Whatever is wrong with 32-bit linux is a separate issue.

@n8sh n8sh added the 72h no objection -> merge The PR will be merged if there are no objections raised. label May 6, 2019
@wilzbach wilzbach merged commit cbc4afc into dlang:master May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
72h no objection -> merge The PR will be merged if there are no objections raised. auto-merge Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants