-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
Make toDelegate
safe for function pointers
#10599
Make toDelegate
safe for function pointers
#10599
Conversation
Thanks for your pull request, @0xEAB! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. 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#10599" |
c569c33
to
89d37f4
Compare
89d37f4
to
65c7071
Compare
65c7071
to
5ebfe85
Compare
Co-authored-by: Elias Batek <[email protected]>
5ebfe85
to
ac35640
Compare
static assert(!is(typeof(&s1.opCall) == delegate)); | ||
S1 s1; |
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.
What’s that doing?
In static assert(!is(typeof(&s1.opCall) == delegate));
, the local variable s1
isn’t in scope.
If you swap the lines, the static assert
passes.
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.
good catch
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.
Apparently, it’s a copy&paste of this code:
Lines 1891 to 1901 in 8c6fca9
struct S1 { int opCall() { inc(myNum); return myNum; } } | |
static assert(!is(typeof(&s1.opCall) == delegate)); | |
S1 s1; | |
auto getvals1 = toDelegate(s1); | |
assert(getvals1() == 4); | |
struct S2 { static int opCall() { return 123456; } } | |
static assert(!is(typeof(&S2.opCall) == delegate)); | |
S2 s2; | |
auto getvals2 =&S2.opCall; | |
assert(getvals2() == 123456); |
https://github.com/dlang/phobos/blame/8c6fca9ccdb30b69b627808c698526a76f7c4248/std/functional.d#L1891-L1901
As discovered by @Bolpat: <dlang#10599 (comment)>
As discovered by @Bolpat: <dlang#10599 (comment)>
As discovered by @Bolpat: <dlang#10599 (comment)>
As discovered by @Bolpat: <#10599 (comment)>
Revamp of #8769.
While I’m not sure whether it covers all use-cases that @Bolpat’s patch had considered and that exist (also see Dennis’ unanswered question over there), it at least passes the testsuite on my machine.
As this is a
@trusted
hack, I’d appreciate my patch to be thoroughly reviewed.