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

UFCS not recognized on array when passing as alias parameter #19112

Open
dlangBugzillaToGithub opened this issue Apr 4, 2016 · 1 comment
Open

Comments

@dlangBugzillaToGithub
Copy link

ryan reported this on 2016-04-04T11:33:20Z

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

CC List

Description

Ordinarily, I don't have to slice an array to treat it as a range. However, when passing it as template alias parameter, it seems like I do:

---
enum test(alias fun) = "it works";

immutable a = [1,2,3];

pragma(msg, test!(a[].map!(x => x))); // OK
pragma(msg, test!(a.map!(x => x)));   // map is not a member of a
pragma(msg, test!(map!(x => x)(a)));   // OK (no UFCS)

// but a.map does work at runtime ...
unittest {
    auto r = a.map!(x => x);
}
---
@dlangBugzillaToGithub
Copy link
Author

gassa commented on 2018-05-25T23:19:00Z

Still does not work in 2.080 release.
The error message however is interesting.
Here is a modified example with a line containing `(a)` instead of `a`.
Compile with `dmd -main`:

-----
import std.algorithm;
enum test(alias fun) = "it works";
immutable a = [1,2,3];

pragma(msg, typeof(a));               // immutable(int[])
pragma(msg, test!((a).map!(x => x))); // "it works"
pragma(msg, test!(a.map!(x => x)));   // template identifier `map` is not a member of variable `a.a`
-----

Why is that `a.a` in the first place?
Does the compiler mistake `a` for an eponymous template somehow, instead of seeing that `map` is a template here?

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