D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14298 - std.typecons.Proxy incorrectly defines opCast operator, that breaks casting to supertype.
Summary: std.typecons.Proxy incorrectly defines opCast operator, that breaks casting t...
Status: RESOLVED DUPLICATE of issue 9249
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-16 23:54 UTC by Lukasz Wrzosek
Modified: 2015-03-18 14:12 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 Lukasz Wrzosek 2015-03-16 23:54:25 UTC
//test case
import std.typecons;
class IA {}
class IB {}
class C : IB {
  IA a;
  mixin Proxy!a;

  public this() {
    a = new IA;
  }
}

void main() {
  C c = new C;
  assert(c !is null);

  IA a = cast(IA)c;
  assert(a !is null);

  IB b_ok = c;
  assert(b_ok !is null); //implicit cast works

  IB b_not_ok = cast(IB)c;
  assert(b_not_ok !is null); //assert fails on explicit cast.
}



//Proxy template always casts to Proxy'ied type:
 auto ref opCast(T, this X)() { return cast(T)a; }
Comment 1 Ali Cehreli 2015-03-18 14:12:48 UTC
Bug 5747 is related as well.

*** This issue has been marked as a duplicate of issue 9249 ***