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

Passing field alias to alias predicate doesn't work, predicate needs explicit instantiation #19629

Open
dlangBugzillaToGithub opened this issue Oct 13, 2019 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Vladimir Panteleev (@CyberShadow) reported this on 2019-10-13T17:25:04Z

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

CC List

  • RazvanN

Description

///////////// test.d /////////////
struct S
{
    int i;
    alias field = i;

    int fun(alias pred)() const
    {
        // Doesn't work:
        //return pred(field);

        // Works:
        alias ipred = pred!int;
        return ipred(field);
    }

    alias fun1 = fun!(i => i + 1);
}
//////////////////////////////////

Error is:

test.d(9,14): Error: template `test.S.__lambda5` cannot deduce function from argument types `!()(const(int)) const`, candidates are:
test.d(16,20):        `__lambda5`
test.d(16,15): Error: template instance `test.S.fun!((i) => i + 1)` error instantiating
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2019-10-15T12:37:10Z

Isn't the real bug here the fact that calling ipred passes compilation? As far as I could tell the lambda template instantion is inside the scope of the S struct => you cannot call it from fun, since fun may call only const functions and pred is mutable.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2019-10-15T12:59:51Z

Thanks for looking at this!

(In reply to RazvanN from comment #1)
> As 
> far as I could tell the lambda template instantion is inside the scope of
> the S struct

Hmm! But, shouldn't it infer that since it doesn't access anything other than its arguments, it should not have a context?

I see that ipred is typed as a function not delegate.

> you cannot call it from fun, since fun may call only const
> functions and pred is mutable.

Thanks, I actually didn't realize that fun being const was a crucial part of this. I guess the error message could be better.

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