[Issue 16655] lambda with type alias parameter fails std.traits.isSomeFunction

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 2 07:20:47 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16655

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |ag0aep6g at gmail.com
         Resolution|---                         |INVALID

--- Comment #3 from ag0aep6g at gmail.com ---
(In reply to Nick Treleaven from comment #0)
> The static asserts below fail:
> 
> struct Color {struct Red {}}
> 
> unittest {
> 	import std.traits;
> 
> 	alias ls = (string) => "string";
> 	static assert(isSomeFunction!ls);
> 
> 	with (Color) {
> 		alias lc = (Red) => "red";
> 		static assert(isSomeFunction!lc);
> 	}
> }

This is a gotcha, but it's not a bug. In a function literal, a single
identifier is interpreted as the name of the parameter, not the type. So
`string` and `Red` do not refer to the types of the same names, but they're
parameter names. Consequently, ls and lc are not functions, but templates,
because the parameters are not typed yet.

Closing as invalid. Please reopen if I'm missing something.

--


More information about the Digitalmars-d-bugs mailing list