On Tuesday, 5 January 2021 at 02:02:39 UTC, kdevel wrote:
expected output: none. The compiler should have rejected the code after the duplicate definition def #2. dmd 2.093.1 ignores both definitions instead. Is this a bug or a bug?

If you try to call .toString directly on a const(S), you get the following error:

onlineapp.d(27): Error: onlineapp.S.toString called with argument types () const matches both:
onlineapp.d(9):     onlineapp.S.toString() const
and:
onlineapp.d(13):     onlineapp.S.toString() const

The reason it is ignored when using writeln is that writeln uses __traits(compiles) to check whether it can call toString on a const(S). Since the call does not compile, it falls back to the default struct formatting code, which produces the output you saw in your example.

Reply via email to