Thread overview
[Issue 11094] Disuniform error messages with overloaded + and ^ operators
Apr 27, 2014
Andrej Mitrovic
May 26, 2022
Ben
Dec 17, 2022
Iain Buclaw
April 27, 2014
https://issues.dlang.org/show_bug.cgi?id=11094

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com

--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
Note that it is unrelated to the overloads, you could have a single opBinary to reproduce:

-----
struct Foo
{
    Foo opBinary(string op)(in Foo r) if (op == "+" || op == "^")
    {
        return Foo();
    }
}

void main()
{
    const x = Foo();
    auto r1 = x + Foo();
    auto r2 = x ^ Foo();
}
-----

--
May 26, 2022
https://issues.dlang.org/show_bug.cgi?id=11094

Ben <ben.james.jones@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ben.james.jones@gmail.com

--- Comment #2 from Ben <ben.james.jones@gmail.com> ---
I took a look at this, and the difference seems to be related to the extra check(s) added at the end of the expressionsem visitors for AddExp vs XorExp:

//in xor only
if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc))
    return setError();


A couple of questions.  This happens earlier in the visitor:

Expression e = exp.op_overload(sc);
if (e)
{
    result = e;
    return;
}


I assume e is null if the op overload doesn't apply (in this case there are constness issues), but putting an error in opover.visitBin seems like maybe the wrong fix?

Those extra checks make sense for xor, is it worth trying to add a supplemental error or something that sees if they tried to do op overloading?

There's a TON of duplication between the addexp and xorexp visitors in expressionsem, and I assume probably with most binop visitors.  Is it worth trying to refactor to reduce the duplication?

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=11094

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--