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

Qualifier dropped from return type when AliasSeq is indexed with template argument #20549

Open
dlangBugzillaToGithub opened this issue Nov 20, 2024 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

Paul Backus (@pbackus) reported this on 2024-11-20T16:34:07Z

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

CC List

Description

As of DMD 2.109.1, the following program fails to compile:

---
alias AliasSeq(Args...) = Args;

struct S
{
    int n;
    ref const(AliasSeq!(int)[i]) get(size_t i)() const => n;
}

void main()
{
    const S s;
    s.get!0;
}
---

The error message is:

---
bug.d(6): Error: expression `this.n` of type `const(int)` is not implicitly convertible to return type `ref int`
bug.d(12): Error: template instance `bug.S.get!0LU` error instantiating
---

As show in the error message, the compiler has erroneously determined the return type of `get!0` to be `int`, when it should instead be `const(int)`.

The same error also occurs with the immutable, inout, and shared qualifiers.
@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2024-11-21T18:07:12Z

Reduced:

struct S
{
    int n;
    ref int get() const => n;
}

void main()
{
    const S s;
    s.get;
}

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2024-11-21T18:12:36Z

>     ref int get() const => n;

Sorry, you're right, ignore comment 1. That should be `ref const(int)`.

It's weird as the function prototype type is OK:

    ref const(AliasSeq!(int)[0]) g() const;
    pragma(msg, typeof(g)); // const ref const(int)()

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2024-11-21T18:16:09Z

OK, making the prototype a template again shows the wrong return type:

    ref const(AliasSeq!(int)[i]) get(size_t i)() const;
    pragma(msg, typeof(get!0)); // const ref int()

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

No branches or pull requests

1 participant