Created attachment 1827
minimized
given a template header such as `struct foo(T,T[] data)`, T[] data appears to mean whatever the first init defined T as
This is across scope, functions and unit tests, if the first initization is int,[1,2,3], and you try string.["a","b","c"], it attempts to parse ["a","b","c"] as an int[]
Comment #1 by crazymonkyyy — 2021-09-22T00:32:19Z
Created attachment 1828
:D
disregard its a feature not a bug
```
struct foo(T,T[] data){
enum data_=data;
}
unittest{
struct sercret{
enum message="i like cake";
}
foo!(sercret,[]) bar;
}
unittest{
alias leet=typeof(foo!(int,[]).data_[0]);
import std.stdio;
leet.message.writeln;
}
```
```
1 monkyyy@no ~/src/statemachines (git)-[master] % dmd -unittest -main -run leethax.d
i like cake
```
Comment #4 by snarwin+bugzilla — 2021-11-04T22:57:51Z
Example program (simplified from attached "minimized" example):
---
template foo(T, T[] somedata_) {}
alias bar = foo!(int, [1, 2, 3]);
alias faz = foo!(string, ["a", "b", "c"]);
---
Expected behavior: compiles successfully.
Actual behavior: fails to compile, with the following error message:
---
Error: template instance `foo!(string, ["a", "b", "c"])` does not match template declaration `foo(T, int[] somedata_)`
---
Removing the line `alias bar = foo!(int, [1, 2, 3]);` causes compilation to succeed.
Comment #5 by maxhaton — 2021-11-05T02:02:34Z
------------------
TemplateInstance.findBestMatch()
foo(T, T[] somedata_) @ 0x7fe5e3c38810 hash is 781bbdffb091
++foo(T, T[] somedata_)
It's a match with template declaration 'foo(T, int[] somedata_)'
++foo(T, int[] somedata_) at end of scope
------------------
Inside findBestMatch it looks like the template is considered and (for the first time round) matches successfully, but the process of doing this actually changes the TemplateDeclaration itself as shown above (see the difference between the two lines marked with pluses).
Comment #6 by nick — 2024-08-22T16:38:45Z
Reading comment 4, this looks like a duplicate of issue 22540.
Comment #7 by robert.schadek — 2024-12-13T19:18:37Z