Skip to content

Conversation

@jmdavis
Copy link
Member

@jmdavis jmdavis commented Dec 1, 2025

This is essentially the same as the one in std.traits except that it only works on types.

It wouldn't surprise me if some folks end up complaining that it requires a type, but it avoids the whole typeof expression vs typeof symbol issue that way. And really, in most situations, if the function can be used as a getter property, then using PropertyType is a better solution anyway (since then it works with variables as well), and if the function cannot be used as a getter property, then getting the type of the actual function call is often a better solution (since that automatically selects the correct overload). But there are still some situations where ReturnType is desirable, and if nothing else, it provides a good place to document what the better alternatives are and why they're better.

As a bonus, the fact that ReturnType only works on types simplifies its implementation.

functionAttributes is mentioned in the documentation for ReturnType, since it's relevant for functions which return by ref, but it's not part of these changes.

This is essentially the same as the one in std.traits except that it
only works on types.

It wouldn't surprise me if some folks end up complaining that it
requires a type, but it avoids the whole typeof expression vs typeof
symbol issue that way. And really, in most situations, if the function
can be used as a getter property, then using PropertyType is a better
solution anyway (since then it works with variables as well), and if the
function cannot be used as a getter property, then getting the type of
the actual function call is often a better solution (since that
automatically selects the correct overload). But there are still some
situations where ReturnType is desirable, and if nothing else, it
provides a good place to document what the better alternatives are and
why they're better.

As a bonus, the fact that ReturnType only works on types simplifies its
implementation.

functionAttributes is mentioned in the documentation for ReturnType,
since it's relevant for functions which return by ref, but it's not part
of these changes.
@jmdavis jmdavis added the Phobos 3 The PR/issue is for Phobos V3. label Dec 1, 2025
@LightBender LightBender merged commit c1d94e1 into dlang:master Dec 1, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Phobos 3 The PR/issue is for Phobos V3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants