Bug 12761 – rvalue object with alias this to lvalue produces rvalue
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-18T07:17:37Z
Last change time
2018-10-25T08:28:09Z
Assigned to
No Owner
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2014-05-18T07:17:37Z
Given an object with an alias this that references an lvalue:
//----
struct S
{
static int i;
alias i this;
}
//----
Then, take two functions that take by auto-ref and ref:
//----
void foo(T)(auto ref T i)
{
pragma(msg, __traits(isRef, i));
}
void bar(ref int i);
//----
Finally, call them with an "RValue s". The alias this from S should create an lvalue int:
//----
void main()
{
foo!int(S());
bar(S());
}
//----
However, it is not the case:
This produces:
false
Error: function main.bar (ref int i) is not callable using argument types (S)
I think this should work.
Comment #1 by razvan.nitu1305 — 2018-10-25T08:24:32Z
This bug report is invalid. Alias this creates a subtyping relation between S and I and should behave as inheritance in the case of classes. Take this example which represents the same pattern but in the case of classes:
class A {}
class B : A {}
void fun(ref A a) {}
void main()
{
fun(new B());
}
You will get the same error:
issue.d(8): Error: function issue.fun(ref A a) is not callable using argument types (B)
issue.d(8): cannot pass rvalue argument new B of type issue.B to parameter ref A a
Comment #2 by razvan.nitu1305 — 2018-10-25T08:27:53Z
This bug report is invalid. Alias this creates a subtyping relation between S and int and should behave as inheritance in the case of classes. Take this example which represents the same pattern but in the case of classes:
class A {}
class B : A {}
void fun(ref A a) {}
void main()
{
fun(new B());
}
You will get the same error:
issue.d(8): Error: function issue.fun(ref A a) is not callable using argument types (B)
issue.d(8): cannot pass rvalue argument new B of type issue.B to parameter ref A a
Closing as invalid.