Bug 12339 – "alias this" not considered for qualified conversion
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-10T12:06:28Z
Last change time
2018-10-23T13:27:54Z
Assigned to
No Owner
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2014-03-10T12:06:28Z
I'd expect an implicit "const S" => "S" conversion to work if an "alias this" call allows it.
//------------
//alias T = int; //OK
alias T = S; //FAIL
static struct S
{
int* p;
T asMutable() const;
alias asMutable this;
}
void main()
{
immutable S s;
T ss = s;
}
//------------
I see this as a needless limitation: The fact that the types match should not prevent the alias this call from happening.
Comment #1 by maxim — 2014-03-10T12:31:44Z
I think it does not work because struct contains pointer. If you comment out it, it will work.
Note that dispite you alias to S type, S itself contains indirections.
//alias T = int; //OK
//alias T = S; //FAIL
alias T = SS; // OK
static struct S
{
int* p;
T asMutable() const { return T(); }
alias asMutable this;
}
struct SS
{
}
void main()
{
immutable S s;
T ss = s;
}
Comment #2 by monarchdodra — 2014-03-10T13:26:18Z
(In reply to comment #1)
> I think it does not work because struct contains pointer. If you comment out
> it, it will work.
>
> Note that dispite you alias to S type, S itself contains indirections.
I know, that was the point. I *wanted* a type were "const(S)" can't be implicitly cast to "S"
The "issue" is that "const(S)" has an alias this to a function that produces an "S", meaning (AFAIK) that according to alias this rules, that this conversion should be considered.
I mean: Why would "alias this" be OK to get an "int", but doesn't work to get an "S"?
Comment #3 by razvan.nitu1305 — 2018-10-23T13:27:54Z