Bug 10197 – [REG2.063] Cannot cast overloaded template property result

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-28T23:31:00Z
Last change time
2013-05-29T15:04:30Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2013-05-28T23:31:25Z
From: http://forum.dlang.org/post/[email protected] This code should work, but doesn't. template OriginalType(T) { static if (is(T U == enum)) alias OriginalType = U; else static assert(0); } enum E : int { F = -20 } struct S { int val; @trusted @property T as(T)() if (is(T == int) && !is(T == enum)) { return cast(T)(val); } @trusted @property T as(T)() if (is(T == enum)) { return cast(T)as!(OriginalType!T); // L21 } } void main() { S val = S(-20); assert(val.as!int == -20); assert(val.as!E == E.F); // L28 } output: test.d(21): Error: cannot cast this.as!(OriginalType!(T)) test.d(28): Error: template instance test.S.as!(E) error instantiating
Comment #1 by k.hara.pg — 2013-05-28T23:37:34Z
Comment #2 by github-bugzilla — 2013-05-29T12:54:22Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0a80b5214ba0e0549c417971fd9842c97bef8abe fix Issue 10197 - Cannot cast overloaded template property result https://github.com/D-Programming-Language/dmd/commit/1f9e6739472c4c15b379563698e720fea7badd4e Merge pull request #2093 from 9rnsr/fix10197 Issue 10197 - [REG2.063] Cannot cast overloaded template property result
Comment #3 by github-bugzilla — 2013-05-29T15:04:30Z
Commits pushed to 2.063 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0b0760a106aaa3fd49da5e4b889115cc70b8d3e8 Merge pull request #2093 from 9rnsr/fix10197 Issue 10197 - [REG2.063] Cannot cast overloaded template property result https://github.com/D-Programming-Language/dmd/commit/8f3b041b390f62a6552fb7324233bdeebe573ba3 Merge pull request #2093 from 9rnsr/fix10197 Issue 10197 - [REG2.063] Cannot cast overloaded template property result