On Tuesday, 19 December 2023 at 23:56:59 UTC, Steven Schveighoffer wrote:
> "static if is an if block that’s executed at compile-time… it doesn’t exist at runtime."
I see what you are going for, but the static if block is included or excluded based on what the compile-time condition is. The condition is executed at compile time, and if the condition is true, the block exists, if not, it doesn't exist. But in the case of your code, clearly the block exists at runtime (you are adding 2 runtime values together).
Hm, I meant that the if
condition, which was static if (is(T: double))
, is evaluated at compile-time and hence, "disappears" at runtime. Did you interpret that as "the whole if block disappears at runtime"? If so, how can I make that clearer that I am talking about the if check, not the branch which gets executed?
Perhaps "static if is evaluated at compile-time, and only the branch that executes is present at runtime, i.e. the if condition itself doesn't exist at runtime"?
> Regarding more descriptive unittests, try out the compiler parameter -checkaction=context
to get more descriptive asserts: https://dlang.org/dmd-osx.html#switch-checkaction
That would be awesome! But it seems there's some problem on my machine:
dmd -L-ld_classic -unittest -checkaction=context -run main.d
Undefined symbols for architecture x86_64:
"__D4core8internal7dassert__T24miniFormatFakeAttributesTiZQBdFNaNbNiNfMKxiZAya", referenced from:
__D4core8internal7dassert__T14_d_assert_failTxiZ__TQxTiZQBcFNaNbNiNfMxAyaMKxiMxiZAya in main.o
__D4core8internal7dassert__T14_d_assert_failTmZ__TQwTiZQBbFNaNbNiNfMxAyaMKxmMxiZAya in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1
Compilation exited abnormally with code 1 at Wed Dec 20 19:34:11
Do you know what this may be? Looks like the Mac OS's linker just doesn't work well with the DMD compiler?!
> there are also options to build your own unittest runner, see https://dlang.org/phobos/core_runtime.html#.Runtime.extendedModuleUnitTester
While this gives you only granularity of the module-level unittests, it allows you to do things like select only certain modules to run. And you do not need to build compile-time lists of all unittests yourself, the compiler links it all together for you (see the example in that function on what the default does).
-Steve
Didn't I mention that in my blog post? Or is this not the same as that example where I showed this:
Runtime.moduleUnitTester = &tester;
Thanks for the feedback, and thanks everyone for the kind words! I really appreciated it :)