From ea9ead9cae18b54017bc8360af2facf844fd9f9e Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 27 Jan 2025 23:23:30 +0100 Subject: [PATCH] Improve opBinary error messages (#20789) --- changelog/dmd.error-messages.dd | 45 +++++ compiler/src/dmd/dcast.d | 2 +- compiler/src/dmd/expressionsem.d | 29 ++- compiler/src/dmd/opover.d | 82 +++++++- compiler/test/fail_compilation/dep_d1_ops.d | 212 ++++++++++++-------- compiler/test/fail_compilation/diag12063.d | 15 +- compiler/test/fail_compilation/diag16499.d | 6 +- compiler/test/fail_compilation/fail297.d | 3 +- compiler/test/fail_compilation/fail3.d | 3 +- compiler/test/fail_compilation/test22329.d | 7 +- 10 files changed, 299 insertions(+), 105 deletions(-) diff --git a/changelog/dmd.error-messages.dd b/changelog/dmd.error-messages.dd index dec114bac1bf..62d362f9cebd 100644 --- a/changelog/dmd.error-messages.dd +++ b/changelog/dmd.error-messages.dd @@ -39,6 +39,51 @@ app.d(6): `app.U` declared here */ --- +When overloading binary operators, and `opBinary` or `opBinaryRight` is missing or doesn't match, +the error message now points out the problem: + +--- +struct Str {} + +struct Number +{ + int x; + int opBinary(string op : "+")(int rhs) => this.x + x; +} + +void f(Str str, Number number) +{ + const s = str ~ "hey"; + const n = number + "oops"; +} + +/* +Before: + +app.d(12): Error: incompatible types for `(str) ~ ("hey")`: `Str` and `string` + const s = str ~ "hey"; + ^ +app.d(13): Error: incompatible types for `(number) + ("oops")`: `Number` and `string` + const n = number + "oops"; + +After: + +app.d(12): Error: operator `~` is not defined for type `Str` + const s = str ~ "hey"; + ^ +app.d(2): perhaps overload the operator with `auto opBinary(string op : "~")(string rhs) {}` +struct Str {} +^ +app.d(13): Error: function `test_.Number.opBinary!"+".opBinary(int rhs)` is not callable using argument types `(string)` + const n = number + "oops"; + ^ +app.d(13): cannot pass argument `"oops"` of type `string` to parameter `int rhs` +app.d(7): `opBinary` defined here + int opBinary(string op : "+")(int rhs) => this.x + x; + ^ +*/ +--- + Furthermore: - D1 operator overloading functions (`opAdd`, `opDot`) are completely removed and no longer mentioned in error messages specifically. diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index 0d95ad46d380..dfc9355415ab 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -4138,7 +4138,7 @@ Expression typeCombine(BinExp be, Scope* sc) { Expression errorReturn() { - Expression ex = be.incompatibleTypes(); + Expression ex = be.incompatibleTypes(sc); if (ex.op == EXP.error) return ex; return ErrorExp.get(); diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 1cf7840d7ad5..d281e1fedefb 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -377,7 +377,7 @@ private Expression incompatibleTypes(UnaExp e) * Returns: * ErrorExp */ -extern (D) Expression incompatibleTypes(BinExp e) +extern (D) Expression incompatibleTypes(BinExp e, Scope* sc = null) { if (e.e1.type.toBasetype() == Type.terror) return e.e1; @@ -386,6 +386,10 @@ extern (D) Expression incompatibleTypes(BinExp e) // CondExp uses 'a ? b : c' but we're comparing 'b : c' const(char)* thisOp = (e.op == EXP.question) ? ":" : EXPtoString(e.op).ptr; + + if (sc && suggestBinaryOverloads(e, sc)) + return ErrorExp.get(); + if (e.e1.op == EXP.type || e.e2.op == EXP.type) { error(e.loc, "incompatible types for `(%s) %s (%s)`: cannot use `%s` with types", @@ -12092,6 +12096,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return; } + if (exp.suggestBinaryOverloads(sc)) + return setError(); + if (exp.checkArithmeticBin()) return setError(); @@ -12245,6 +12252,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return; } + if (exp.suggestBinaryOverloads(sc)) + return setError(); + if (exp.checkArithmeticBin()) return setError(); @@ -12578,6 +12588,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return true; } + if (exp.suggestBinaryOverloads(sc)) + { + setError(); + return true; + } + if (exp.checkArithmeticBin() || exp.checkSharedAccessBin(sc)) { setError(); @@ -12792,6 +12808,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return; } + if (exp.suggestBinaryOverloads(sc)) + return setError(); + if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc)) return setError(); @@ -12862,6 +12881,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor result = exp.incompatibleTypes(); return; } + + if (exp.suggestBinaryOverloads(sc)) + return setError(); + if (exp.checkIntegralBin() || exp.checkSharedAccessBin(sc)) return setError(); @@ -13119,7 +13142,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return setError(); case Tarray, Tsarray: - result = exp.incompatibleTypes(); + result = exp.incompatibleTypes(sc); errorSupplemental(exp.loc, "`in` is only allowed on associative arrays"); const(char)* slice = (t2b.ty == Tsarray) ? "[]" : ""; errorSupplemental(exp.loc, "perhaps use `std.algorithm.find(%s, %s%s)` instead", @@ -13127,7 +13150,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor return; default: - result = exp.incompatibleTypes(); + result = exp.incompatibleTypes(sc); return; } result = exp; diff --git a/compiler/src/dmd/opover.d b/compiler/src/dmd/opover.d index 92f3bb2ebd32..c547e2f4fbdb 100644 --- a/compiler/src/dmd/opover.d +++ b/compiler/src/dmd/opover.d @@ -71,6 +71,29 @@ bool isCommutative(EXP op) @safe return false; } +/// Returns: whether `op` can be overloaded with `opBinary` +private bool hasOpBinary(EXP op) pure @safe +{ + switch (op) + { + case EXP.add: return true; + case EXP.min: return true; + case EXP.mul: return true; + case EXP.div: return true; + case EXP.mod: return true; + case EXP.and: return true; + case EXP.or: return true; + case EXP.xor: return true; + case EXP.leftShift: return true; + case EXP.rightShift: return true; + case EXP.unsignedRightShift: return true; + case EXP.concatenate: return true; + case EXP.pow: return true; + case EXP.in_: return true; + default: return false; + } +} + /******************************************* * Helper function to turn operator into template argument list */ @@ -591,12 +614,63 @@ Expression opOverloadBinary(BinExp e, Scope* sc, Type[2] aliasThisStop) s_r = null; bool choseReverse; - if (auto res = pickBestBinaryOverload(sc, opToArg(sc, e.op), s, s_r, e, choseReverse)) - return res; + if (auto result = pickBestBinaryOverload(sc, opToArg(sc, e.op), s, s_r, e, choseReverse)) + return result; return binAliasThis(e, sc, aliasThisStop); } +/** + * If applicable, print an error relating to implementing / fixing `opBinary` functions. + * Params: + * e = binary operation + * sc = scope to try `opBinary!""` semantic in for error messages + * Returns: `true` when an error related to `opBinary` was printed + */ +bool suggestBinaryOverloads(BinExp e, Scope* sc) +{ + if (!e.op.hasOpBinary) + return false; + + AggregateDeclaration ad1 = isAggregate(e.e1.type); + AggregateDeclaration ad2 = isAggregate(e.e2.type); + + if (ad1) + { + if (Dsymbol s = search_function(ad1, Id.opBinary)) + { + dotTemplate(e.e1, Id.opBinary, opToArg(sc, e.op), e.e2).expressionSemantic(sc); + errorSupplemental(s.loc, "`opBinary` defined here"); + return true; + } + error(e.loc, "operator `%s` is not defined for type `%s`", EXPtoString(e.op).ptr, e.e1.type.toChars); + errorSupplemental(ad1.loc, "perhaps overload the operator with `auto opBinary(string op : \"%s\")(%s rhs) {}`", EXPtoString(e.op).ptr, e.e2.type.toChars); + return true; + } + else if (ad2) + { + if (Dsymbol s_r = search_function(ad1, Id.opBinaryRight)) + { + dotTemplate(e.e2, Id.opBinaryRight, opToArg(sc, e.op), e.e1).expressionSemantic(sc); + errorSupplemental(s_r.loc, "`opBinaryRight` defined here"); + return true; + } + error(e.loc, "operator `%s` is not defined for type `%s`", EXPtoString(e.op).ptr, e.e2.type.toChars); + errorSupplemental(ad2.loc, "perhaps overload the operator with `auto opBinaryRight(string op : \"%s\")(%s rhs) {}`", EXPtoString(e.op).ptr, e.e1.type.toChars); + return true; + } + return false; +} + +// Helper to construct e.id!tiargs(arg) +private Expression dotTemplate(Expression e, Identifier id, Objects* tiargs, Expression arg) +{ + auto ti = new DotTemplateInstanceExp(e.loc, e, id, tiargs); + auto args = new Expressions(); + args.push(arg); + return new CallExp(e.loc, ti, args); +} + Expression opOverloadEqual(EqualExp e, Scope* sc, Type[2] aliasThisStop) { Type t1 = e.e1.type.toBasetype(); @@ -990,7 +1064,7 @@ private Expression pickBestBinaryOverload(Scope* sc, Objects* tiargs, Dsymbol s, if (s) { - functionResolve(m, s, e.loc, sc, tiargs, e.e1.type, ArgumentList(args2)); + functionResolve(m, s, e.loc, sc, tiargs, e.e1.type, ArgumentList(args2), null); if (m.lastf && (m.lastf.errors || m.lastf.hasSemantic3Errors())) return ErrorExp.get(); } @@ -998,7 +1072,7 @@ private Expression pickBestBinaryOverload(Scope* sc, Objects* tiargs, Dsymbol s, int count = m.count; if (s_r) { - functionResolve(m, s_r, e.loc, sc, tiargs, e.e2.type, ArgumentList(args1)); + functionResolve(m, s_r, e.loc, sc, tiargs, e.e2.type, ArgumentList(args1), null); if (m.lastf && (m.lastf.errors || m.lastf.hasSemantic3Errors())) return ErrorExp.get(); } diff --git a/compiler/test/fail_compilation/dep_d1_ops.d b/compiler/test/fail_compilation/dep_d1_ops.d index f8ebc37f8019..ec1a0f1c8575 100644 --- a/compiler/test/fail_compilation/dep_d1_ops.d +++ b/compiler/test/fail_compilation/dep_d1_ops.d @@ -2,89 +2,135 @@ REQUIRED_ARGS: TEST_OUTPUT: --- -fail_compilation/dep_d1_ops.d(198): Error: incompatible types for `(s) + (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(199): Error: incompatible types for `(1) + (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(200): Error: incompatible types for `(s) - (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(201): Error: incompatible types for `(1) - (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(202): Error: incompatible types for `(s) * (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(203): Error: incompatible types for `(1) * (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(204): Error: incompatible types for `(s) / (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(205): Error: incompatible types for `(1) / (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(206): Error: incompatible types for `(s) % (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(207): Error: incompatible types for `(1) % (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(209): Error: incompatible types for `(s) & (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(210): Error: incompatible types for `(s) | (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(211): Error: incompatible types for `(s) ^ (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(213): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(214): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(215): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(216): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(217): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(218): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(220): Error: incompatible types for `(s) ~ (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(221): Error: incompatible types for `(1) ~ (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(223): Error: operator `+` is not defined for `s` of type `S` -fail_compilation/dep_d1_ops.d(224): Error: operator `-` is not defined for `s` of type `S` -fail_compilation/dep_d1_ops.d(225): Error: `s` is not of integral type, it is a `S` -fail_compilation/dep_d1_ops.d(226): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(227): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(228): Error: can only `*` a pointer, not a `S` -fail_compilation/dep_d1_ops.d(230): Error: incompatible types for `(s) in (1)`: `S` and `int` -fail_compilation/dep_d1_ops.d(231): Error: incompatible types for `(1) in (s)`: `int` and `S` -fail_compilation/dep_d1_ops.d(233): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(234): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(235): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(236): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(237): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(238): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(239): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(240): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(241): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(242): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(243): Error: `s` is not a scalar, it is a `S` -fail_compilation/dep_d1_ops.d(244): Error: cannot append type `int` to type `S` -fail_compilation/dep_d1_ops.d(248): Error: incompatible types for `(c) + (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(249): Error: incompatible types for `(1) + (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(250): Error: incompatible types for `(c) - (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(251): Error: incompatible types for `(1) - (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(252): Error: incompatible types for `(c) * (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(253): Error: incompatible types for `(1) * (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(254): Error: incompatible types for `(c) / (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(255): Error: incompatible types for `(1) / (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(256): Error: incompatible types for `(c) % (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(257): Error: incompatible types for `(1) % (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(259): Error: incompatible types for `(c) & (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(260): Error: incompatible types for `(c) | (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(261): Error: incompatible types for `(c) ^ (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(263): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(264): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(265): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(266): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(267): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(268): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(270): Error: incompatible types for `(c) ~ (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(271): Error: incompatible types for `(1) ~ (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(273): Error: operator `+` is not defined for `c` of type `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(274): Error: operator `-` is not defined for `c` of type `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(275): Error: `c` is not of integral type, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(276): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(277): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(278): Error: can only `*` a pointer, not a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(280): Error: incompatible types for `(c) in (1)`: `dep_d1_ops.C` and `int` -fail_compilation/dep_d1_ops.d(281): Error: incompatible types for `(1) in (c)`: `int` and `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(283): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(284): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(285): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(286): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(287): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(288): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(289): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(290): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(291): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(292): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(293): Error: `c` is not a scalar, it is a `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(294): Error: cannot append type `int` to type `dep_d1_ops.C` -fail_compilation/dep_d1_ops.d(303): Error: `nd` is not of integral type, it is a `dep_d1_ops.NoDeprecation` +fail_compilation/dep_d1_ops.d(244): Error: operator `+` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}` +fail_compilation/dep_d1_ops.d(245): Error: operator `+` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int rhs) {}` +fail_compilation/dep_d1_ops.d(246): Error: operator `-` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "-")(int rhs) {}` +fail_compilation/dep_d1_ops.d(247): Error: operator `-` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int rhs) {}` +fail_compilation/dep_d1_ops.d(248): Error: operator `*` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "*")(int rhs) {}` +fail_compilation/dep_d1_ops.d(249): Error: operator `*` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int rhs) {}` +fail_compilation/dep_d1_ops.d(250): Error: operator `/` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "/")(int rhs) {}` +fail_compilation/dep_d1_ops.d(251): Error: operator `/` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int rhs) {}` +fail_compilation/dep_d1_ops.d(252): Error: operator `%` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "%")(int rhs) {}` +fail_compilation/dep_d1_ops.d(253): Error: operator `%` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int rhs) {}` +fail_compilation/dep_d1_ops.d(255): Error: operator `&` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "&")(int rhs) {}` +fail_compilation/dep_d1_ops.d(256): Error: operator `|` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "|")(int rhs) {}` +fail_compilation/dep_d1_ops.d(257): Error: operator `^` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "^")(int rhs) {}` +fail_compilation/dep_d1_ops.d(259): Error: operator `<<` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "<<")(int rhs) {}` +fail_compilation/dep_d1_ops.d(260): Error: operator `<<` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int rhs) {}` +fail_compilation/dep_d1_ops.d(261): Error: operator `>>` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : ">>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(262): Error: operator `>>` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(263): Error: operator `>>>` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : ">>>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(264): Error: operator `>>>` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(266): Error: operator `~` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "~")(int rhs) {}` +fail_compilation/dep_d1_ops.d(267): Error: operator `~` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int rhs) {}` +fail_compilation/dep_d1_ops.d(269): Error: operator `+` is not defined for `s` of type `S` +fail_compilation/dep_d1_ops.d(270): Error: operator `-` is not defined for `s` of type `S` +fail_compilation/dep_d1_ops.d(271): Error: `s` is not of integral type, it is a `S` +fail_compilation/dep_d1_ops.d(272): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(273): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(274): Error: can only `*` a pointer, not a `S` +fail_compilation/dep_d1_ops.d(276): Error: operator `in` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinary(string op : "in")(int rhs) {}` +fail_compilation/dep_d1_ops.d(277): Error: operator `in` is not defined for type `S` +fail_compilation/dep_d1_ops.d(137): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}` +fail_compilation/dep_d1_ops.d(279): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(280): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(281): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(282): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(283): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(284): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(285): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(286): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(287): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(288): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(289): Error: `s` is not a scalar, it is a `S` +fail_compilation/dep_d1_ops.d(290): Error: cannot append type `int` to type `S` +fail_compilation/dep_d1_ops.d(294): Error: operator `+` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}` +fail_compilation/dep_d1_ops.d(295): Error: operator `+` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int rhs) {}` +fail_compilation/dep_d1_ops.d(296): Error: operator `-` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "-")(int rhs) {}` +fail_compilation/dep_d1_ops.d(297): Error: operator `-` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int rhs) {}` +fail_compilation/dep_d1_ops.d(298): Error: operator `*` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "*")(int rhs) {}` +fail_compilation/dep_d1_ops.d(299): Error: operator `*` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int rhs) {}` +fail_compilation/dep_d1_ops.d(300): Error: operator `/` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "/")(int rhs) {}` +fail_compilation/dep_d1_ops.d(301): Error: operator `/` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int rhs) {}` +fail_compilation/dep_d1_ops.d(302): Error: operator `%` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "%")(int rhs) {}` +fail_compilation/dep_d1_ops.d(303): Error: operator `%` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int rhs) {}` +fail_compilation/dep_d1_ops.d(305): Error: operator `&` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "&")(int rhs) {}` +fail_compilation/dep_d1_ops.d(306): Error: operator `|` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "|")(int rhs) {}` +fail_compilation/dep_d1_ops.d(307): Error: operator `^` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "^")(int rhs) {}` +fail_compilation/dep_d1_ops.d(309): Error: operator `<<` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "<<")(int rhs) {}` +fail_compilation/dep_d1_ops.d(310): Error: operator `<<` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int rhs) {}` +fail_compilation/dep_d1_ops.d(311): Error: operator `>>` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : ">>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(312): Error: operator `>>` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(313): Error: operator `>>>` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : ">>>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(314): Error: operator `>>>` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int rhs) {}` +fail_compilation/dep_d1_ops.d(316): Error: operator `~` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "~")(int rhs) {}` +fail_compilation/dep_d1_ops.d(317): Error: operator `~` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int rhs) {}` +fail_compilation/dep_d1_ops.d(319): Error: operator `+` is not defined for `c` of type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(320): Error: operator `-` is not defined for `c` of type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(321): Error: `c` is not of integral type, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(322): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(323): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(324): Error: can only `*` a pointer, not a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(326): Error: operator `in` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinary(string op : "in")(int rhs) {}` +fail_compilation/dep_d1_ops.d(327): Error: operator `in` is not defined for type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(188): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}` +fail_compilation/dep_d1_ops.d(329): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(330): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(331): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(332): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(333): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(334): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(335): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(336): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(337): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(338): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(339): Error: `c` is not a scalar, it is a `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(340): Error: cannot append type `int` to type `dep_d1_ops.C` +fail_compilation/dep_d1_ops.d(349): Error: `nd` is not of integral type, it is a `dep_d1_ops.NoDeprecation` --- */ diff --git a/compiler/test/fail_compilation/diag12063.d b/compiler/test/fail_compilation/diag12063.d index 3e9535ab4210..9d81dba346ce 100644 --- a/compiler/test/fail_compilation/diag12063.d +++ b/compiler/test/fail_compilation/diag12063.d @@ -1,13 +1,14 @@ /* TEST_OUTPUT: --- -fail_compilation/diag12063.d(19): Error: cannot check `diag12063.Bar.b` value for overflow -fail_compilation/diag12063.d(16): Error: no property `max` for type `Foo`, perhaps `import std.algorithm;` is needed? -fail_compilation/diag12063.d(19): Error: cannot generate value for `diag12063.Bar.b` -fail_compilation/diag12063.d(19): Error: incompatible types for `(Foo()) + (1)`: `Bar` and `int` -fail_compilation/diag12063.d(29): Error: cannot check `diag12063.b` value for overflow -fail_compilation/diag12063.d(29): Error: incompatible types for `(S()) == (1)`: `S` and `int` -fail_compilation/diag12063.d(38): Error: enum member `diag12063.d` initialization with `__anonymous.c+1` causes overflow for type `Q` +fail_compilation/diag12063.d(20): Error: cannot check `diag12063.Bar.b` value for overflow +fail_compilation/diag12063.d(17): Error: no property `max` for type `Foo`, perhaps `import std.algorithm;` is needed? +fail_compilation/diag12063.d(20): Error: cannot generate value for `diag12063.Bar.b` +fail_compilation/diag12063.d(20): Error: operator `+` is not defined for type `Bar` +fail_compilation/diag12063.d(15): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}` +fail_compilation/diag12063.d(30): Error: cannot check `diag12063.b` value for overflow +fail_compilation/diag12063.d(30): Error: incompatible types for `(S()) == (1)`: `S` and `int` +fail_compilation/diag12063.d(39): Error: enum member `diag12063.d` initialization with `__anonymous.c+1` causes overflow for type `Q` --- */ diff --git a/compiler/test/fail_compilation/diag16499.d b/compiler/test/fail_compilation/diag16499.d index 63b4b3c52795..f3757954d4a3 100644 --- a/compiler/test/fail_compilation/diag16499.d +++ b/compiler/test/fail_compilation/diag16499.d @@ -1,8 +1,10 @@ /* TEST_OUTPUT: --- -fail_compilation/diag16499.d(22): Error: incompatible types for `(2) in (foo)`: `int` and `A` -fail_compilation/diag16499.d(24): Error: incompatible types for `(1.0) in (bar)`: `double` and `B` +fail_compilation/diag16499.d(24): Error: operator `in` is not defined for type `A` +fail_compilation/diag16499.d(11): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}` +fail_compilation/diag16499.d(26): Error: operator `in` is not defined for type `B` +fail_compilation/diag16499.d(12): perhaps overload the operator with `auto opBinaryRight(string op : "in")(double rhs) {}` --- */ diff --git a/compiler/test/fail_compilation/fail297.d b/compiler/test/fail_compilation/fail297.d index 3bb25dd0fae4..f74b814c187f 100644 --- a/compiler/test/fail_compilation/fail297.d +++ b/compiler/test/fail_compilation/fail297.d @@ -1,7 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/fail297.d(30): Error: operator `+` is not defined for `Bar()` of type `Bar` +fail_compilation/fail297.d(31): Error: operator `+` is not defined for type `Bar` +fail_compilation/fail297.d(25): perhaps overload the operator with `auto opBinary(string op : "+")(const(Bar) rhs) {}` --- */ diff --git a/compiler/test/fail_compilation/fail3.d b/compiler/test/fail_compilation/fail3.d index 1c40c4f93c76..bcc9614db656 100644 --- a/compiler/test/fail_compilation/fail3.d +++ b/compiler/test/fail_compilation/fail3.d @@ -1,7 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/fail3.d(41): Error: operator `+` is not defined for `a` of type `vec2` +fail_compilation/fail3.d(42): Error: operator `+` is not defined for type `vec2` +fail_compilation/fail3.d(13): perhaps overload the operator with `auto opBinary(string op : "+")(vec2 rhs) {}` --- */ diff --git a/compiler/test/fail_compilation/test22329.d b/compiler/test/fail_compilation/test22329.d index 25c83f5142d6..a6e152ce1d11 100644 --- a/compiler/test/fail_compilation/test22329.d +++ b/compiler/test/fail_compilation/test22329.d @@ -4,9 +4,10 @@ TEST_OUTPUT: --- fail_compilation/imports/imp22329.d(3): Error: no property `values` for type `test22329.Foo` -fail_compilation/test22329.d(13): struct `Foo` defined here -fail_compilation/imports/imp22329.d(3): Error: incompatible types for `(arg) + (1)`: `Foo` and `int` -fail_compilation/test22329.d(21): Error: template instance `imp22329.func!(Foo)` error instantiating +fail_compilation/test22329.d(14): struct `Foo` defined here +fail_compilation/imports/imp22329.d(3): Error: operator `+` is not defined for type `Foo` +fail_compilation/test22329.d(14): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}` +fail_compilation/test22329.d(22): Error: template instance `imp22329.func!(Foo)` error instantiating --- */