Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias this incorrectly invoked in conversion to ref #19466

Open
dlangBugzillaToGithub opened this issue Jul 26, 2018 · 2 comments
Open

Alias this incorrectly invoked in conversion to ref #19466

dlangBugzillaToGithub opened this issue Jul 26, 2018 · 2 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

RazvanN (@RazvanN7) reported this on 2018-07-26T11:20:08Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19117

CC List

  • Simen Kjaeraas

Description

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.
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2018-07-26T11:22:28Z

(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

@dlangBugzillaToGithub
Copy link
Author

simen.kjaras commented on 2018-07-26T12:07:09Z

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant