D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23118 - UFCS not working for function level templates
Summary: UFCS not working for function level templates
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-17 10:54 UTC by RazvanN
Modified: 2022-05-17 11:03 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 2022-05-17 10:54:17 UTC
This code fails:

```
void main()
{
    static void func(T)(T a, T b) { }
    
    2.func!int(2);   // Error: no property `func` for type `int`
}
```

whereas this code compiles fine:

```
static void func(T)(T a, T b) { }

void main()
{    
    2.func!int(2);
}
```

I haven't found anything in the spec about this case, but I don't see why ufcs would not be considered in the former case.
Comment 1 Dennis 2022-05-17 11:01:11 UTC
This is intentionally disallowed, though it is sometimes requested as an improvement.

https://dlang.org/spec/function.html#pseudo-member

> Functions declared in a local scope are not found when searching for a matching UFCS function.
Comment 2 RazvanN 2022-05-17 11:02:21 UTC
Cool, closing as invalid.
Comment 3 Dennis 2022-05-17 11:03:39 UTC
Some code relies on the current behavior by the way:

http://dpldocs.info/this-week-in-d/Blog.Posted_2022_01_31.html#tip-of-the-week