D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10237 - std.typecons.Proxy doesn't work with overloaded member function
Summary: std.typecons.Proxy doesn't work with overloaded member function
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-02 02:33 UTC by SHOO
Modified: 2024-12-13 18:07 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 SHOO 2013-06-02 02:33:19 UTC
This code doesn't work:

import std.typecons;

struct A(T)
{
private:
	T* _p;
	ref inout(T) _instance() inout { return *cast(inout(T)*)_p; }
	ref immutable(T) _instance() immutable { return *cast(immutable(T)*)_p; }
	ref shared(T) _instance() shared { return *cast(shared(T)*)_p; }
	ref const(shared(T)) _instance() const shared { return *cast(const(shared(T))*)_p; }
public:
	mixin Proxy!(_instance);
}

struct B(T)
{
private:
	T* _p;
	@property ref inout(T) _instance() inout { return *cast(inout(T)*)_p; }
	@property ref immutable(T) _instance() immutable { return *cast(immutable(T)*)_p; }
	@property ref shared(T) _instance() shared { return *cast(shared(T)*)_p; }
	@property ref const(shared(T)) _instance() const shared { return *cast(const(shared(T))*)_p; }
public:
	mixin Proxy!(_instance);
}

void main()
{
	static struct Foo { @property int foo(){return 0;} }
	alias A!Foo AFoo;
	AFoo af;
	af._p = new Foo;
	assert(af.foo == 0); // NG
	alias B!Foo BFoo; // NG
	BFoo bf;
	bf._p = new Foo;
	assert(bf.foo == 0);
}
Comment 1 Kenji Hara 2013-06-02 03:46:26 UTC
The root issue is : std.typecons.Proxy does not consider the case which forwarding target is overloaded member function.

This is essential test code.

struct A(T)
{
private:
    T* _p;
    ref auto _instance() inout        { return *cast(       inout(T) *)_p; }
    ref auto _instance() immutable    { return *cast(   immutable(T) *)_p; }
    ref auto _instance() shared       { return *cast(      shared(T) *)_p; }
    ref auto _instance() const shared { return *cast(const(shared(T))*)_p; }
public:
    //import std.typecons;
    //mixin Proxy!(_instance);

    pragma(msg, typeof(_instance.foo));   // L17 problem1
    pragma(msg, __traits(getOverloads, _instance, "foo").length);   // L28 problem2
}
void main()
{
    static struct Foo { @property int foo(){ return 0; } }
    alias AFoo = A!Foo;
    AFoo af;
}

In above, L17 and L18 are mostly same check as Proxy does. They try to test _instance.foo ==> _instance().foo, but the places L17 and L18 have no valid 'this' context. So, compiler cannot determine actual function from overloaded _instance call, then reports ambiguity.
Comment 2 berni44 2019-11-14 13:18:17 UTC
Seems to be a dmd bug and not a phobos bug.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:07:25 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18594

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB