www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug?

reply Elfstone <elfstone yeah.net> writes:
```D
struct Matrix(S, size_t M, size_t N)
{
}

alias Vec3(S) = Matrix!(S, 3, 1);

void main()
{
     import std.stdio;

     writeln(is(Vec3!float == Matrix!(S, 3, 1), S)); // `alias` 
`S` is defined here
     writeln(is(Matrix!(float, 3, 1) == Matrix!(S, 3, 1), S)); // 
Error: declaration `S` is already defined
}
```

Even though the following code compiles.

```D
     writeln(is(Vec3!float == Matrix!(S, 3, 1), S));
     writeln(is(Vec3!float == Matrix!(S, 3, 1), S));
```
Mar 15 2023
parent reply Elfstone <elfstone yeah.net> writes:
On Thursday, 16 March 2023 at 03:40:04 UTC, Elfstone wrote:
 ```D
 struct Matrix(S, size_t M, size_t N)
 {
 }

 alias Vec3(S) = Matrix!(S, 3, 1);

 void main()
 {
     import std.stdio;

     writeln(is(Vec3!float == Matrix!(S, 3, 1), S)); // `alias` 
 `S` is defined here
     writeln(is(Matrix!(float, 3, 1) == Matrix!(S, 3, 1), S)); 
 // Error: declaration `S` is already defined
 }
 ```

 Even though the following code compiles.

 ```D
     writeln(is(Vec3!float == Matrix!(S, 3, 1), S));
     writeln(is(Vec3!float == Matrix!(S, 3, 1), S));
 ```
Oops, the above code compiles, because I added comments!!! Now this really doesn't compile: ```D struct Matrix(S, size_t M, size_t N) { } alias Vec3(S) = Matrix!(S, 3, 1); void main() { import std.stdio; writeln(is(Vec3!float == Matrix!(S, 3, 1), S)); writeln(is(Matrix!(float, 3, 1) == Matrix!(S, 3, 1), S)); } ```
Mar 15 2023
parent reply Elfstone <elfstone yeah.net> writes:
On Thursday, 16 March 2023 at 03:44:19 UTC, Elfstone wrote:
 On Thursday, 16 March 2023 at 03:40:04 UTC, Elfstone wrote:
 [...]
Oops, the above code compiles, because I added comments!!! Now this really doesn't compile: ```D struct Matrix(S, size_t M, size_t N) { } alias Vec3(S) = Matrix!(S, 3, 1); void main() { import std.stdio; writeln(is(Vec3!float == Matrix!(S, 3, 1), S)); writeln(is(Matrix!(float, 3, 1) == Matrix!(S, 3, 1), S)); } ```
Correction. With or without comments, mostly it doesn't compile, occasionally it does! I have no idea.
Mar 15 2023
parent reply Elfstone <elfstone yeah.net> writes:
On Thursday, 16 March 2023 at 04:04:51 UTC, Elfstone wrote:
 On Thursday, 16 March 2023 at 03:44:19 UTC, Elfstone wrote:
 On Thursday, 16 March 2023 at 03:40:04 UTC, Elfstone wrote:
 [...]
Oops, the above code compiles, because I added comments!!! Now this really doesn't compile: ```D struct Matrix(S, size_t M, size_t N) { } alias Vec3(S) = Matrix!(S, 3, 1); void main() { import std.stdio; writeln(is(Vec3!float == Matrix!(S, 3, 1), S)); writeln(is(Matrix!(float, 3, 1) == Matrix!(S, 3, 1), S)); } ```
Correction. With or without comments, mostly it doesn't compile, occasionally it does! I have no idea.
I can't get it to compile anymore, it must be some mistake from me. Maybe I forgot to save while modifying the code. So the `S` declared in `is` expression can contaminate the scope? Is this supposed to happen?
Mar 15 2023
parent Elfstone <elfstone yeah.net> writes:
On Thursday, 16 March 2023 at 04:31:11 UTC, Elfstone wrote:
 On Thursday, 16 March 2023 at 04:04:51 UTC, Elfstone wrote:
 On Thursday, 16 March 2023 at 03:44:19 UTC, Elfstone wrote:
 [...]
Correction. With or without comments, mostly it doesn't compile, occasionally it does! I have no idea.
I can't get it to compile anymore, it must be some mistake from me. Maybe I forgot to save while modifying the code. So the `S` declared in `is` expression can contaminate the scope? Is this supposed to happen?
Never mind, I just found out this is supposed to happen, `S` is supposed to be available later. https://dlang.org/spec/expression.html#is-parameter-list
Mar 15 2023