Bug 11401 – ElementType returns constructor instead of type
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-31T09:42:00Z
Last change time
2013-11-04T07:11:56Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
jcrapuchettes
Comments
Comment #0 by jcrapuchettes — 2013-10-31T09:42:06Z
Using latest git HEAD, the following code produces an error where 2.063.2 does not. It appears to be a problem with either std.range.ElementType or std.traits.lvalueOf.
Code
---
import std.range;
void main()
{
alias ElementType!RowRange E;
static assert(is(typeof(E.id)), E.stringof~" is expected to have a 'id' member");
}
struct RowRange
{
BasicNode front()
{
return BasicNode.init;
}
}
struct BasicNode { ushort id; }
Output
---
$ ~/dmd-git/build/bin/dmd serialize.d
test.d(6): Error: static assert "BasicNode() is expected to have a 'id' member"
Comment #1 by andrei — 2013-11-03T13:44:30Z
Turns out it's a compiler bug, not a library one. I reduced the code to:
struct RowRange
{
BasicNode front()
{
return BasicNode.init;
}
}
struct BasicNode { ushort id; }
void main()
{
alias E1 = typeof(RowRange.init.front());
static assert(is(typeof(E1.id)),
E1.stringof~" is expected to have a 'id' member");
alias E2 = typeof(RowRange.init.front);
static assert(is(typeof(E2.id)),
E2.stringof~" is expected to have a 'id' member");
}
Comment #2 by k.hara.pg — 2013-11-03T18:33:49Z
This is git-head only issue.
Introduced by:
https://github.com/D-Programming-Language/phobos/pull/1658
(In reply to comment #1)
> alias E1 = typeof(RowRange.init.front());
> static assert(is(typeof(E1.id)),
> E1.stringof~" is expected to have a 'id' member");
> alias E2 = typeof(RowRange.init.front);
> static assert(is(typeof(E2.id)),
> E2.stringof~" is expected to have a 'id' member");
Currently typeof(non_property_func) returns the function type, not its return type. It is intended behavior, and this is not a compiler issue.