www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12339] New: "alais this" not considered for qualified conversion

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12339

           Summary: "alais this" not considered for qualified conversion
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2014-03-10 12:06:28 PDT ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12339


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2014-03-10 12:31:44 PDT
---
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;
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12339



--- Comment #2 from monarchdodra gmail.com 2014-03-10 13:26:18 PDT ---
(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"? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2014