Thread overview
Undefined aliases as compile time flags and import arguments
4 days ago
monkyyy
2 days ago
monkyyy
3 days ago
Nick Treleaven
3 days ago
Dennis
4 days ago
alias A;//now compiles as a no op
alias A;
void foo()=>A;//fails A is undefined
#! dmd -A=3.14 -run
alias A;
void foo()=>A;//compiles, returns 3.14;
struct myint{int i;}
import test(A:myint(6.28));
unittest{
  foo.writeln;//myint(6.28);
}
3 days ago

On Tuesday, 22 April 2025 at 16:00:50 UTC, monkyyy wrote:

>
#! dmd -A=3.14 -run
alias A;
void foo()=>A;//compiles, returns 3.14;

I’m not sure how well this approach would scale with larger projects. In particular it seems to bypass/ignore the module system provided by the language.

3 days ago

On Tuesday, 22 April 2025 at 16:00:50 UTC, monkyyy wrote:

>
alias A;
void foo()=>A;//fails A is undefined

Presumably the above is module test;.

>
struct myint{int i;}
import test(A:myint(6.28));
unittest{
  foo.writeln;//myint(6.28);
}

That seems to have the effect of the test module itself being a template taking a template parameter A.

Just to mention, this was not easy to work was going on in your example (regardless of whether the module is a template or not). There is a style convention of types (myint) being capitalized and values (A) being lower case.

3 days ago

On Tuesday, 22 April 2025 at 16:00:50 UTC, monkyyy wrote:

>
#! dmd -A=3.14 -run
alias A;
void foo()=>A;//compiles, returns 3.14;

Something like this has been proposed before, and rejected to prevent facilitating overly complex build processes: https://github.com/dlang/dmd/pull/15257#issuecomment-1585835222

2 days ago

On Wednesday, 23 April 2025 at 00:28:07 UTC, Elias Batek (0xEAB) wrote:

>

On Tuesday, 22 April 2025 at 16:00:50 UTC, monkyyy wrote:

>
#! dmd -A=3.14 -run
alias A;
void foo()=>A;//compiles, returns 3.14;

I’m not sure how well this approach would scale with larger projects. In particular it seems to bypass/ignore the module system provided by the language.

It directly engages with the module system