digitalmars.D.bugs - [Issue 4989] New: opDispatch not used when alias this is present
- d-bugmail puremagic.com (61/61) Oct 04 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4989
- d-bugmail puremagic.com (10/10) Nov 30 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4989
- d-bugmail puremagic.com (11/11) Nov 30 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4989
http://d.puremagic.com/issues/show_bug.cgi?id=4989
Summary: opDispatch not used when alias this is present
Product: D
Version: D2
Platform: Other
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: schveiguy yahoo.com
10:38:27 PDT ---
Example:
import std.stdio;
struct X
{
int foo() { return 1; }
bool foo2() {return true;}
}
struct S
{
X x;
// override only int functions
auto opDispatch(string fn, Args...)(Args args) if (is(typeof(mixin("x." ~
fn ~ "(args)")) == int))
{
writeln("calling " ~ fn);
mixin("return x." ~ fn ~ "(args);");
}
// override functions that aren't supported by X
void opDispatch(string fn, Args...)(Args args) if (!is(typeof(mixin("x." ~
fn ~ "(args)"))))
{
writeln("invalid function " ~ fn);
}
// let all others pass through (i.e. foo2)
alias x this;
}
void main()
{
S s;
s.foo();
s.foo2();
// s.baz(); // compiler error "Error: no property 'baz' for type 'X'"
}
when compiled, this outputs nothing. I'd expect to see (if last line of main
is uncommented):
calling foo
invalid function baz
Note the glaring use case here is being able to have an implicit cast, yet
override the behavior of the implicitly casted member.
At the very least, opDispatch should be used when the alias this'd value does
not support the function.
IMO, opDispatch should be preferred over the alias this'd member. Simply
because it's possible (though ugly) to select which opDispatch functions
compile, but it's impossible to selectively pick members to compile via alias
this.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4989
Simen Kjaeraas <simen.kjaras gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pelle.mansson gmail.com
PST ---
*** Issue 4224 has been marked as a duplicate of this issue. ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 30 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4989
Steven Schveighoffer <schveiguy yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
05:25:15 PST ---
*** This issue has been marked as a duplicate of issue 4224 ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 30 2010









d-bugmail puremagic.com 