Bug 16655 – lambda with type alias parameter fails std.traits.isSomeFunction

Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2016-11-02T10:43:00Z
Last change time
2016-11-02T14:20:47Z
Assigned to
nobody
Creator
nick

Comments

Comment #0 by nick — 2016-11-02T10:43:51Z
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); } } If you define ls, lc like this it works: alias ls = (immutable(char)[]) => "string"; alias lc = (Color.Red) => "red";
Comment #1 by nick — 2016-11-02T10:45:58Z
Workaround is to add parameter names: alias ls = (string s) => "string"; alias lc = (Red r) => "red";
Comment #2 by nick — 2016-11-02T10:48:41Z
BTW parameter names aren't needed because the lambdas are used for Algebraic().visit!Lambdas: http://forum.dlang.org/post/[email protected]
Comment #3 by ag0aep6g — 2016-11-02T14:20:47Z
(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.