@@ -262,7 +262,7 @@ private Expression checkAliasThisForRhs(AggregateDeclaration ad, Scope* sc, BinE
262262 * sc = context
263263 * pop = if not null, is set to the operator that was actually overloaded,
264264 * which may not be `e.op`. Happens when operands are reversed to
265- * to match an overload
265+ * match an overload
266266 * Returns:
267267 * `null` if not an operator overload,
268268 * otherwise the lowered expression
@@ -917,52 +917,13 @@ Expression op_overload(Expression e, Scope* sc, TOK* pop = null)
917917 Type t1 = e.e1.type.toBasetype();
918918 Type t2 = e.e2.type.toBasetype();
919919
920- /* Check for array equality.
920+ /* Array equality is lowered to object.__equals(), which takes care
921+ * of overloaded operators for the element types.
921922 */
922923 if ((t1.ty == Tarray || t1.ty == Tsarray) &&
923924 (t2.ty == Tarray || t2.ty == Tsarray))
924925 {
925- bool needsDirectEq ()
926- {
927- Type t1n = t1.nextOf().toBasetype();
928- Type t2n = t2.nextOf().toBasetype();
929- if ((t1n.ty.isSomeChar && t2n.ty.isSomeChar) ||
930- (t1n.ty == Tvoid || t2n.ty == Tvoid))
931- {
932- return false ;
933- }
934- if (t1n.constOf() != t2n.constOf())
935- return true ;
936-
937- Type t = t1n;
938- while (t.toBasetype().nextOf())
939- t = t.nextOf().toBasetype();
940- if (t.ty != Tstruct)
941- return false ;
942-
943- if (global.params.useTypeInfo && Type.dtypeinfo)
944- semanticTypeInfo(sc, t);
945-
946- return (cast (TypeStruct)t).sym.hasIdentityEquals;
947- }
948-
949- if (needsDirectEq() && ! (t1.ty == Tarray && t2.ty == Tarray))
950- {
951- /* Rewrite as:
952- * __ArrayEq(e1, e2)
953- */
954- Expression eeq = new IdentifierExp(e.loc, Id.__ArrayEq);
955- result = new CallExp(e.loc, eeq, e.e1, e.e2);
956- if (e.op == TOK .notEqual)
957- result = new NotExp(e.loc, result);
958- result = result.trySemantic(sc); // for better error message
959- if (! result)
960- {
961- e.error(" cannot compare `%s` and `%s`" , t1.toChars(), t2.toChars());
962- result = new ErrorExp();
963- }
964- return ;
965- }
926+ return ;
966927 }
967928
968929 /* Check for class equality with null literal or typeof(null).
@@ -1028,9 +989,6 @@ Expression op_overload(Expression e, Scope* sc, TOK* pop = null)
1028989 return ;
1029990 }
1030991
1031- if (t1.ty == Tarray && t2.ty == Tarray)
1032- return ;
1033-
1034992 /* Check for pointer equality.
1035993 */
1036994 if (t1.ty == Tpointer || t2.ty == Tpointer)
0 commit comments