[Issue 20661] opEquals not recognized for AA key (take two)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 18 16:20:49 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=20661

--- Comment #2 from RazvanN <razvan.nitu1305 at gmail.com> ---
This is very problematic. When `size_t[const(Key)] aa;` is analyzed it jumps to
analyzing `Key` to see if it defines an opEquals that could be called in this
scenario. During the semantic analysis of Key, xopEquals is also generated: if
we have a `const bool opEquals(ref const S s);` that's fine, no need to do
anything else, but opEquals might also be templated. In the latter situation an
_xopEquals is generated that simply returns whether `this == param`. Because of
that the body of xopEquals needs to be analyzed: to see if the template
opEquals is callable in this fashion. If it is, then the AA key is valid, if
not then it is assumed that the opEquals provided is not correct. This is the
actual issue: for non-templated opEquals analyzing the body eagerly results in
forward reference issues. That is what is happening here: we proceed to analyze
Key, we identify the opEquals and we eagerly start analyzing it's body. When we
get to the `auto c = context.checkAll;` line we need to analyze context,
therefore we need to analyze `class Context` (because `checkAll` might be an
overlapped pointer field) => forward reference error.

I'm not sure how this can be fixed.

--


More information about the Digitalmars-d-bugs mailing list