D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6980 - Disallow shadowing template parameters
Summary: Disallow shadowing template parameters
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
: 14516 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-11-20 07:48 UTC by Kyle Foley
Modified: 2024-12-13 17:57 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kyle Foley 2011-11-20 07:48:44 UTC
This example compiles in 2.056

---
struct A(T)
{
	T func(T)(T rhs)
	{
		return rhs;
	}
}

void main()
{
	A!(int) a;
	
	a.func("test");
}
---
Comment 1 Infiltrator 2014-03-19 22:02:54 UTC
This could certainly be a source of unexpected bugs.  Has anybody dug into this?
Comment 2 Bolpat 2023-12-12 11:40:29 UTC
The general sense of when shadowing a symbol is an error or not is if the symbol has an unambiguous way to be referenced. This expectation is broken when template parameters are shadowed:

```d
struct S(T)
{
    alias T = int; // no error!?
    T x;
    pragma(msg, typeof(x)); // int
}
S!double unused;
```
Comment 3 basile-z 2023-12-13 10:44:09 UTC
This is a bug given that you cant select the first definition.

However, this should works when T is an alias template parameter and that T is either a function or an overload set. 

That is not the case now:

```d
struct S(alias T)
{
    alias T = (int) => 0;

    void test()
    {
        T(0.1); // Error: function literal `__lambda3(int __param_0)` is not callable 
                // using argument types `(double)`

        T(1);
    }
}

void main(string[] args)
{
    S!((float) => 0) s1;
} 
```
Comment 4 basile-z 2023-12-16 18:23:53 UTC
*** Issue 14516 has been marked as a duplicate of this issue. ***
Comment 5 dlangBugzillaToGithub 2024-12-13 17:57:00 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17533

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB