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.
Comment #3 by k.hara.pg — 2013-11-03T19:15:28Z
Comment #4 by github-bugzilla — 2013-11-04T03:37:13Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/a9eb6219b4d03ace4e6688eaeb3dfcd4f90a9faf fix Issue 11401 - ElementType returns constructor instead of type 1. For `exp.member`, compiler always try to resolve property/optional parenthesis on `exp`. so use `front.init`. 2. Built-in `init` property always returns rvalue, so `front.init` won't invoke postblit. https://github.com/D-Programming-Language/phobos/commit/d743e6caa9c52e53f6bac38fb925d46b65071f78 Merge pull request #1681 from 9rnsr/fix11401 [REG2.065a] Issue 11401 - ElementType returns constructor instead of type