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 17722 - Wrong diagnostic using __traits(compiles, e1 && e2) expressions #7067

Merged
merged 1 commit into from
Aug 8, 2017

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Aug 6, 2017

Manipulates e1 and e2 in a local e1x and e2x var respectively, and assigns them back if semantic was successful.

This is the same as what other binary expressions do via binSemantic/binSemanticProp.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

Bugzilla references

Auto-close Bugzilla Description
17722 Wrong diagnostic using __traits(compiles, e1 && e2) expressions.

if (f1 || f2)
{
result = new ErrorExp();
return;
}

if (exp.e2.type.ty == Tvoid)
if (e2x.type.ty == Tvoid)
Copy link
Member

Choose a reason for hiding this comment

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

By assigning to exp.type here, the type gets disconnected from the operands, putting exp into an invalid state. A better approach is to assign to a t here, and assign exp.type = t; when the operands are assigned.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, you mean that if the first time round the caller ignores the propagated error and runs semantic on this expression again?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is to say, setting type means that you are saying this expression has completed its semantic, when infact it could instead return error (in which case, semantic did not complete).

Copy link
Member

Choose a reason for hiding this comment

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

That's right. Even if it doesn't, it looks suspicious, which will cause extra work for anyone trying to understand the code.

exp.type = Type.tvoid;
else
{
exp.e2 = exp.e2.toBoolean(sc);
e2x = e2x.toBoolean(sc);
Copy link
Member

Choose a reason for hiding this comment

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

here too

return;
}

exp.e1 = e1x;
exp.e2 = e2x;
Copy link
Member

Choose a reason for hiding this comment

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

Put exp.type = t; here.

if (f1 || f2)
{
result = new ErrorExp();
return;
}

if (exp.e2.type.ty == Tvoid)
if (e2x.type.ty == Tvoid)
Copy link
Member

Choose a reason for hiding this comment

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

same problem as above.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 7, 2017

Actually in this case, as the logic in-between setting exp.type, and returning the result is just error propagation, I can just move the setting of exp.type to the end, so that a temporary is not needed.

@WalterBright
Copy link
Member

When fixing a bugzilla issue, please put the PR URL in the bugzilla issue, so somebody else doesn't waste time trying to fix it because he's ignorant there is an extant fix already.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

I still think that the cross reference should be handled by the dlang bot/whatever github hook posts messages to bugzilla on commits.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

Fixed the wrong filename in the test output.

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

Tests pass.

@@ -0,0 +1,13 @@
/* TEST_OUTPUT:
Copy link
Member

Choose a reason for hiding this comment

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

Please merge these two test files into one. It'll consume half the resources of the autotester that way.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's kept as two separate because the compiler doesn't issue an error for both when together in the same file.

@WalterBright
Copy link
Member

WalterBright commented Aug 8, 2017

You'd have had half the work to do if you'd pulled #7069 :-)

@ibuclaw
Copy link
Member Author

ibuclaw commented Aug 8, 2017

You'd have had half the work to do if you'd pulled #7069 :-)

I'd still end up doing double work, because then I'd have to rebase this PR.

@dlang-bot dlang-bot merged commit bfee6b3 into dlang:master Aug 8, 2017
@ibuclaw ibuclaw deleted the issue17722 branch August 9, 2017 07:28
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