D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19117 - Alias this incorrectly invoked in conversion to ref
Summary: Alias this incorrectly invoked in conversion to ref
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-26 11:20 UTC by RazvanN
Modified: 2024-12-13 18:59 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 RazvanN 2018-07-26 11:20:08 UTC
struct A
{
    immutable(A) fun() { return  immutable A(); }
    ref A fun2(ref A a)  { return this; }                                                                                                          

    alias fun this;    // line 6
}

void main()
{
    A a, b;
    b.fun2(a);
}

aliasthisbug.d(12): Error: function aliasthisbug.A.fun2(ref A a) is not callable using argument types (A)
aliasthisbug.d(12):        cannot pass argument a of type A to parameter ref A a

Comment line 6 an the error disappears.
Comment 1 RazvanN 2018-07-26 11:22:28 UTC
(In reply to RazvanN from comment #0)
> struct A
> {
>     immutable(A) fun() { return  immutable A(); }
>     ref A fun2(ref A a)  { return this; }                                   
> 
> 
>     alias fun this;    // line 6
> }
> 
> void main()
> {
>     A a, b;
>     b.fun2(a);
> }
> 
> aliasthisbug.d(12): Error: function aliasthisbug.A.fun2(ref A a) is not
> callable using argument types (A)
> aliasthisbug.d(12):        cannot pass argument a of type A to parameter ref
> A a
> 
> Comment line 6 an the error disappears.

Also, changing the signature of fun2 to : ref A fun2(A a) makes the example compile
Comment 2 Simen Kjaeraas 2018-07-26 12:07:09 UTC
Further simplified:

struct A {
    const(A) fun();
    alias fun this;
}

void fun2(ref A a);

unittest {
    A a;
    fun2(a);
}

This bug triggers when the alias this type is a qualified version of A (shared, const, or immutable), and A has no aliasing (pointers, dynamic arrays, AAs).
Comment 3 dlangBugzillaToGithub 2024-12-13 18:59:52 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

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

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