dmd 2.093.1: duplicate method definitions ignored altogether
Paul Backus
snarwin at gmail.com
Tue Jan 5 03:36:47 UTC 2021
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.
More information about the Digitalmars-d-learn
mailing list