Skip to content

Fix Issue 18430 - isSame is wrong for non global lambdas#7885

Merged
wilzbach merged 1 commit intodlang:masterfrom
RazvanN7:Issue_18430
Feb 13, 2018
Merged

Fix Issue 18430 - isSame is wrong for non global lambdas#7885
wilzbach merged 1 commit intodlang:masterfrom
RazvanN7:Issue_18430

Conversation

@RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Feb 13, 2018

The code in the bug report:

template Alias(alias a)
{
    alias Alias = a;
}

auto foo()
{
    auto scale = 4;
    alias edentity = a => a * scale;
    static assert(__traits(isSame, Alias!edentity, edentity)); // fails in dmd-nightly
}

__traits(isSame) compares either 2 dsymbols or 2 lambda functions. Since an alias to a lambda function is considered to be both (a dsymbol and a lambda function), __traits(isSame) will first check that the lambda functions are indeed identical and the result will be false, since lambdas which have template instantiations as arguments are considered to be incomparable. On the other hand, if treated as dsymbols, the result will be true.

The fix is pretty simple: if 2 lambda functions are not equal __traits will not return false, but check if the parameters are equal dsymbols.

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 13, 2018

Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
18430 regression isSame is wrong for non global lambdas

@9il
Copy link
Member

9il commented Feb 13, 2018

Thank you!

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.

Thanks!

@wilzbach wilzbach merged commit 01fb3ca into dlang:master Feb 13, 2018
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.

5 participants