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
Infer noreturn for auto functions #12553
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request and interest in making D better, @MoonlightSentinel! 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 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 + dmd#12553" |
This PR currently has a negative implication for callbacks as seen in the druntime failure: void fun(void function() f);
void fun(void delegate() d);
fun(() { throw new Exception(""); }); The call above is now ambiguous because both overloads are considered as equal ( |
40106a1
to
a854cf4
Compare
a854cf4
to
8364adb
Compare
Resolved the ambiguity by upping the matching level for Another possible approach would be to adapt the matching code for function / delegate literals, allthough that wouldn't be as encapsulated as the current approach. This currently fails because of the dreaded |
Really not a fan of putting special-case hacks like this in the type system. This is the kind of decision that can seem like the lesser of two evils at the time, but that future D programmers will end up cursing us for. The correct solution is to disambiguate the call in druntime by giving the function literal an explicit return type. (Arguably, the actual correct solution is to implement implicit conversion of |
8364adb
to
e0d3b1b
Compare
dlang/dmd#12553 will change the return type inference s.t. these lambdas are inferred as `noreturn` instead of `void`. This causes an ambiguity regarding the `void function()` and the `void delegate` overloads.
dlang/dmd#12553 will change the return type inference s.t. these lambdas are inferred as `noreturn` instead of `void`. This causes an ambiguity regarding the `void function()` and the `void delegate` overloads.
e0d3b1b
to
8096f1a
Compare
8096f1a
to
0a18072
Compare
0a18072
to
26f1733
Compare
dlang/dmd#12553 will enable the frontend to infer `noreturn` as the return type of templated / auto functions. The unittest fails with this PR because `collideWith(Asteroid, Spaceship)` always throws an exception and hence is inferred as `noreturn`. This causes `collide(Asteroid, Spaceship)` to return `string` instead of `void` because `noreturn` is implicitly convertible to any type.
dlang/dmd#12553 will enable the frontend to infer `noreturn` as the return type of templated / auto functions. The unittest fails with this PR because `collideWith(Asteroid, Spaceship)` always throws an exception and hence is inferred as `noreturn`. This causes `collide(Asteroid, Spaceship)` to return `string` instead of `void` because `noreturn` is implicitly convertible to any type.
dlang/dmd#12553 will enable the frontend to infer `noreturn` as the return type of templated / auto functions. The unittest fails with this PR because `collideWith(Asteroid, Spaceship)` always throws an exception and hence is inferred as `noreturn`. This causes `collide(Asteroid, Spaceship)` to return `string` instead of `void` because `noreturn` is implicitly convertible to any type.
616c4f9
to
e9c8c37
Compare
Infer noreturn whenever the function body is never exited normally
e9c8c37
to
3b69861
Compare
@MoonlightSentinel What is the state of this draft? |
Infer noreturn whenever the function body is never exited normally.
Also added a bunch of tests from the DIP that really should've been added in the initial PR's... (because many of them don't work)
Required changes:
return
in collectException[Msg]... phobos#8264asynAwaitAny
for noreturn callbacks vibe-d/vibe-core#299Related changes: