June 13, 2023

Only a small thing, but is it intended that:

void main() {

// static assert (false, "Static Assert triggered");
   assert(false, "Assert triggered");

}

produces

core.exception.AssertError@staticassertex01.d(4): Assert triggered

but removing the // produces

staticassertex01.d(3): Error: static assert:  "Static Assert triggered"

ie message surrounded by double-quotes?

June 13, 2023

On Tuesday, 13 June 2023 at 16:46:26 UTC, DLearner wrote:

>

Only a small thing, but is it intended that:

void main() {

// static assert (false, "Static Assert triggered");
   assert(false, "Assert triggered");

}

produces

core.exception.AssertError@staticassertex01.d(4): Assert triggered

but removing the // produces

staticassertex01.d(3): Error: static assert:  "Static Assert triggered"

ie message surrounded by double-quotes?

internal detail.

Static assert will render the message by formatting an AST node, i.e the StringExp (as the string has to be statically evaluable), using a compiler module called the hdrgen, leading to have the double quotes included, because the hdrgen is supposed to give back the source code for a particulat node.

Runtime assert only know the string ptr and len, which are runtime values. So... in that case it's more like a format %s, that takes another path.