Thread overview
[Issue 17239] template this in typeof expressions
Mar 02, 2017
John Colvin
Sep 14, 2022
Nick Treleaven
Sep 14, 2022
Nick Treleaven
Sep 14, 2022
John Colvin
March 02, 2017
https://issues.dlang.org/show_bug.cgi?id=17239

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |blocker

--- Comment #1 from John Colvin <john.loughran.colvin@gmail.com> ---
In order to add typeof(AggregateType.member) support to std.typecons.Proxy (with knockon improvements to a few other things in std.typecons), either this bug or https://issues.dlang.org/show_bug.cgi?id=17240 needs resolving.

--
September 14, 2022
https://issues.dlang.org/show_bug.cgi?id=17239

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #2 from Nick Treleaven <nick@geany.org> ---
>     @property int b(this X)() { return 2; }

If you change b above to c (I assume it's a typo), you get:

int
int()
void

As c is a template, the type is supposed to be void. This is nothing to do with the template this parameter.

--
September 14, 2022
https://issues.dlang.org/show_bug.cgi?id=17239

--- Comment #3 from Nick Treleaven <nick@geany.org> ---
> As c is a template, the type is supposed to be void

This got added to the spec fairly recently:

> If the expression is a Template, typeof gives the type void.

https://dlang.org/spec/type.html#typeof

--
September 14, 2022
https://issues.dlang.org/show_bug.cgi?id=17239

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #4 from John Colvin <john.loughran.colvin@gmail.com> ---
(In reply to Nick Treleaven from comment #2)
> >     @property int b(this X)() { return 2; }
> 
> If you change b above to c (I assume it's a typo), you get:
> 
> int
> int()
> void
> 
> As c is a template, the type is supposed to be void. This is nothing to do with the template this parameter.

Yes, a typo.

I suppose that means this is a wontfix. typeof is weird, e.g.

typeof(a.b) c = a.b;

doesn’t actually work generically (aside from copy-ability concerns). I understand why it is this way, but it would be nice if the docs actually explained what it was supposed to do.

The type of an expression is… well it depends what that expression part of. The “Full Expression” section is not very enlightening.

--