digitalmars.D.learn - static foreach declaration already defined
- Ssenni (15/15) Aug 27 How can I get around this?
- Richard (Rikki) Andrew Cattermole (10/12) Aug 27 Double braces isn't a thing.
- drug007 (11/31) Aug 27 This is because in D static foreach does not create new scope and all
- drug007 (1/1) Aug 27 Ah, sorry, I rushed
- Adam D. Ruppe (3/4) Aug 27 Use OpenD instead. We fix obvious bugs like this to make the
- Ssenni (3/5) Aug 27 I do use OpenD! I wanted to make it work with both compilers.
- Adam D. Ruppe (3/4) Aug 27 yeah, wrapper template of the is() thing is really the only way
How can I get around this?
```
struct Foo(T) {
static foreach (m; __traits(derivedMembers, T)) {
static foreach (i, method; __traits(getOverloads, T, m)) {
static if (is(typeof(method) Params == __parameters)) {
}
}
}
}
```
Error: declaration `Params` is already defined here.
If I recall, there used to be a trick for static foreach using
double braces, but the compiler complains "declaration expected
not {".
Aug 27
On 27/08/2026 9:40 PM, Ssenni wrote:
If I recall, there used to be a trick for static foreach using double
braces, but the compiler complains "declaration expected not {".
Double braces isn't a thing.
What you've seen is a scope statement.
```d
void func() {
{
}
}
```
Since you're working as a declaration of course it won't work.
Aug 27
On 8/27/26 12:40, Ssenni wrote:
How can I get around this?
```
struct Foo(T) {
static foreach (m; __traits(derivedMembers, T)) {
static foreach (i, method; __traits(getOverloads, T, m)) {
static if (is(typeof(method) Params == __parameters)) {
}
}
}
}
```
Error: declaration `Params` is already defined here.
If I recall, there used to be a trick for static foreach using double
braces, but the compiler complains "declaration expected not {".
This is because in D static foreach does not create new scope and all
iterations are executed within the same scope, which leads to the error.
You need to explicitly add the scope:
```
static foreach(..){
static foreach (...) {{ // <-- note double curly braces
...
}} // <-- note double curly braces
}
```
Aug 27
On Thursday, 27 August 2026 at 09:40:15 UTC, Ssenni wrote:How can I get around this?Use OpenD instead. We fix obvious bugs like this to make the language work the way it should.
Aug 27
On Thursday, 27 August 2026 at 11:15:49 UTC, Adam D. Ruppe wrote:Use OpenD instead. We fix obvious bugs like this to make the language work the way it should.I do use OpenD! I wanted to make it work with both compilers. I'll just use a template instead.
Aug 27
On Thursday, 27 August 2026 at 11:29:10 UTC, Ssenni wrote:I'll just use a template instead.yeah, wrapper template of the is() thing is really the only way to do it in upstream.
Aug 27









"Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> 