D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10197 - [REG2.063] Cannot cast overloaded template property result
Summary: [REG2.063] Cannot cast overloaded template property result
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-05-28 23:31 UTC by Kenji Hara
Modified: 2013-05-29 15:04 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2013-05-28 23:31:25 UTC
From: http://forum.dlang.org/post/pjgyejdfumdpupgjjajv@forum.dlang.org

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 2 github-bugzilla 2013-05-29 12:54:22 UTC
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 github-bugzilla 2013-05-29 15:04:30 UTC
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