Skip to content

Commit 102c02d

Browse files
committed
Fix opBinaryRight error message to suggest lhs instead of rhs
1 parent 67bd5a5 commit 102c02d

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

compiler/src/dmd/opover.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ bool suggestBinaryOverloads(BinExp e, Scope* sc)
612612
return true;
613613
}
614614
error(e.loc, "operator `%s` is not defined for type `%s`", EXPtoString(e.op).ptr, e.e2.type.toChars);
615-
errorSupplemental(ad2.loc, "perhaps overload the operator with `auto opBinaryRight(string op : \"%s\")(%s rhs) {}`", EXPtoString(e.op).ptr, e.e1.type.toChars);
615+
errorSupplemental(ad2.loc, "perhaps overload the operator with `auto opBinaryRight(string op : \"%s\")(%s lhs) {}`", EXPtoString(e.op).ptr, e.e1.type.toChars);
616616
return true;
617617
}
618618
return false;

compiler/test/fail_compilation/dep_d1_ops.d

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ TEST_OUTPUT:
55
fail_compilation/dep_d1_ops.d(281): Error: operator `+` is not defined for type `S`
66
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}`
77
fail_compilation/dep_d1_ops.d(282): Error: operator `+` is not defined for type `S`
8-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int rhs) {}`
8+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int lhs) {}`
99
fail_compilation/dep_d1_ops.d(283): Error: operator `-` is not defined for type `S`
1010
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "-")(int rhs) {}`
1111
fail_compilation/dep_d1_ops.d(284): Error: operator `-` is not defined for type `S`
12-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int rhs) {}`
12+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int lhs) {}`
1313
fail_compilation/dep_d1_ops.d(285): Error: operator `*` is not defined for type `S`
1414
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "*")(int rhs) {}`
1515
fail_compilation/dep_d1_ops.d(286): Error: operator `*` is not defined for type `S`
16-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int rhs) {}`
16+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int lhs) {}`
1717
fail_compilation/dep_d1_ops.d(287): Error: operator `/` is not defined for type `S`
1818
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "/")(int rhs) {}`
1919
fail_compilation/dep_d1_ops.d(288): Error: operator `/` is not defined for type `S`
20-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int rhs) {}`
20+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int lhs) {}`
2121
fail_compilation/dep_d1_ops.d(289): Error: operator `%` is not defined for type `S`
2222
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "%")(int rhs) {}`
2323
fail_compilation/dep_d1_ops.d(290): Error: operator `%` is not defined for type `S`
24-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int rhs) {}`
24+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int lhs) {}`
2525
fail_compilation/dep_d1_ops.d(292): Error: operator `&` is not defined for type `S`
2626
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "&")(int rhs) {}`
2727
fail_compilation/dep_d1_ops.d(293): Error: operator `|` is not defined for type `S`
@@ -31,19 +31,19 @@ fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `a
3131
fail_compilation/dep_d1_ops.d(296): Error: operator `<<` is not defined for type `S`
3232
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "<<")(int rhs) {}`
3333
fail_compilation/dep_d1_ops.d(297): Error: operator `<<` is not defined for type `S`
34-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int rhs) {}`
34+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int lhs) {}`
3535
fail_compilation/dep_d1_ops.d(298): Error: operator `>>` is not defined for type `S`
3636
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : ">>")(int rhs) {}`
3737
fail_compilation/dep_d1_ops.d(299): Error: operator `>>` is not defined for type `S`
38-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int rhs) {}`
38+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int lhs) {}`
3939
fail_compilation/dep_d1_ops.d(300): Error: operator `>>>` is not defined for type `S`
4040
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : ">>>")(int rhs) {}`
4141
fail_compilation/dep_d1_ops.d(301): Error: operator `>>>` is not defined for type `S`
42-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int rhs) {}`
42+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int lhs) {}`
4343
fail_compilation/dep_d1_ops.d(303): Error: operator `~` is not defined for type `S`
4444
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "~")(int rhs) {}`
4545
fail_compilation/dep_d1_ops.d(304): Error: operator `~` is not defined for type `S`
46-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int rhs) {}`
46+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int lhs) {}`
4747
fail_compilation/dep_d1_ops.d(306): Error: operator `+` is not defined for `S`
4848
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opUnary(string op : "+")() {}`
4949
fail_compilation/dep_d1_ops.d(307): Error: operator `-` is not defined for `S`
@@ -59,7 +59,7 @@ fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `a
5959
fail_compilation/dep_d1_ops.d(313): Error: operator `in` is not defined for type `S`
6060
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinary(string op : "in")(int rhs) {}`
6161
fail_compilation/dep_d1_ops.d(314): Error: operator `in` is not defined for type `S`
62-
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}`
62+
fail_compilation/dep_d1_ops.d(174): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int lhs) {}`
6363
fail_compilation/dep_d1_ops.d(316): Error: operator `+=` not supported for `s` of type `S`
6464
fail_compilation/dep_d1_ops.d(174): perhaps implement `auto opOpAssign(string op : "+")(int) {}`
6565
fail_compilation/dep_d1_ops.d(317): Error: operator `-=` not supported for `s` of type `S`
@@ -87,23 +87,23 @@ fail_compilation/dep_d1_ops.d(174): perhaps implement `auto opOpAssign(st
8787
fail_compilation/dep_d1_ops.d(331): Error: operator `+` is not defined for type `dep_d1_ops.C`
8888
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "+")(int rhs) {}`
8989
fail_compilation/dep_d1_ops.d(332): Error: operator `+` is not defined for type `dep_d1_ops.C`
90-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int rhs) {}`
90+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "+")(int lhs) {}`
9191
fail_compilation/dep_d1_ops.d(333): Error: operator `-` is not defined for type `dep_d1_ops.C`
9292
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "-")(int rhs) {}`
9393
fail_compilation/dep_d1_ops.d(334): Error: operator `-` is not defined for type `dep_d1_ops.C`
94-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int rhs) {}`
94+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "-")(int lhs) {}`
9595
fail_compilation/dep_d1_ops.d(335): Error: operator `*` is not defined for type `dep_d1_ops.C`
9696
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "*")(int rhs) {}`
9797
fail_compilation/dep_d1_ops.d(336): Error: operator `*` is not defined for type `dep_d1_ops.C`
98-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int rhs) {}`
98+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "*")(int lhs) {}`
9999
fail_compilation/dep_d1_ops.d(337): Error: operator `/` is not defined for type `dep_d1_ops.C`
100100
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "/")(int rhs) {}`
101101
fail_compilation/dep_d1_ops.d(338): Error: operator `/` is not defined for type `dep_d1_ops.C`
102-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int rhs) {}`
102+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int lhs) {}`
103103
fail_compilation/dep_d1_ops.d(339): Error: operator `%` is not defined for type `dep_d1_ops.C`
104104
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "%")(int rhs) {}`
105105
fail_compilation/dep_d1_ops.d(340): Error: operator `%` is not defined for type `dep_d1_ops.C`
106-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int rhs) {}`
106+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "%")(int lhs) {}`
107107
fail_compilation/dep_d1_ops.d(342): Error: operator `&` is not defined for type `dep_d1_ops.C`
108108
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "&")(int rhs) {}`
109109
fail_compilation/dep_d1_ops.d(343): Error: operator `|` is not defined for type `dep_d1_ops.C`
@@ -113,19 +113,19 @@ fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `a
113113
fail_compilation/dep_d1_ops.d(346): Error: operator `<<` is not defined for type `dep_d1_ops.C`
114114
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "<<")(int rhs) {}`
115115
fail_compilation/dep_d1_ops.d(347): Error: operator `<<` is not defined for type `dep_d1_ops.C`
116-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int rhs) {}`
116+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "<<")(int lhs) {}`
117117
fail_compilation/dep_d1_ops.d(348): Error: operator `>>` is not defined for type `dep_d1_ops.C`
118118
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : ">>")(int rhs) {}`
119119
fail_compilation/dep_d1_ops.d(349): Error: operator `>>` is not defined for type `dep_d1_ops.C`
120-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int rhs) {}`
120+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : ">>")(int lhs) {}`
121121
fail_compilation/dep_d1_ops.d(350): Error: operator `>>>` is not defined for type `dep_d1_ops.C`
122122
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : ">>>")(int rhs) {}`
123123
fail_compilation/dep_d1_ops.d(351): Error: operator `>>>` is not defined for type `dep_d1_ops.C`
124-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int rhs) {}`
124+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : ">>>")(int lhs) {}`
125125
fail_compilation/dep_d1_ops.d(353): Error: operator `~` is not defined for type `dep_d1_ops.C`
126126
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "~")(int rhs) {}`
127127
fail_compilation/dep_d1_ops.d(354): Error: operator `~` is not defined for type `dep_d1_ops.C`
128-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int rhs) {}`
128+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "~")(int lhs) {}`
129129
fail_compilation/dep_d1_ops.d(356): Error: operator `+` is not defined for `C`
130130
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opUnary(string op : "+")() {}`
131131
fail_compilation/dep_d1_ops.d(357): Error: operator `-` is not defined for `C`
@@ -141,7 +141,7 @@ fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `a
141141
fail_compilation/dep_d1_ops.d(363): Error: operator `in` is not defined for type `dep_d1_ops.C`
142142
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinary(string op : "in")(int rhs) {}`
143143
fail_compilation/dep_d1_ops.d(364): Error: operator `in` is not defined for type `dep_d1_ops.C`
144-
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}`
144+
fail_compilation/dep_d1_ops.d(225): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int lhs) {}`
145145
fail_compilation/dep_d1_ops.d(366): Error: operator `+=` not supported for `c` of type `C`
146146
fail_compilation/dep_d1_ops.d(225): perhaps implement `auto opOpAssign(string op : "+")(int) {}`
147147
fail_compilation/dep_d1_ops.d(367): Error: operator `-=` not supported for `c` of type `C`

compiler/test/fail_compilation/diag16499.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
TEST_OUTPUT:
33
---
44
fail_compilation/diag16499.d(24): Error: operator `in` is not defined for type `A`
5-
fail_compilation/diag16499.d(11): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int rhs) {}`
5+
fail_compilation/diag16499.d(11): perhaps overload the operator with `auto opBinaryRight(string op : "in")(int lhs) {}`
66
fail_compilation/diag16499.d(26): Error: operator `in` is not defined for type `B`
7-
fail_compilation/diag16499.d(12): perhaps overload the operator with `auto opBinaryRight(string op : "in")(double rhs) {}`
7+
fail_compilation/diag16499.d(12): perhaps overload the operator with `auto opBinaryRight(string op : "in")(double lhs) {}`
88
---
99
*/
1010

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/issue22147.d(15): Error: operator `/` is not defined for type `T`
5+
fail_compilation/issue22147.d(9): perhaps overload the operator with `auto opBinaryRight(string op : "/")(int lhs) {}`
6+
---
7+
*/
8+
9+
struct T
10+
{
11+
}
12+
13+
void main()
14+
{
15+
auto result = 10 / T(); // int / T requires opBinaryRight on T
16+
}

0 commit comments

Comments
 (0)