// Checks that some operators come in pairs: // == and != // > and < // >= and <= // true and false // // They are matched based on the return type and the argument types void CheckPairedOp(ResolveContext rc) { bool has_equality_or_inequality = false; List <OperatorType> found_matched = new List <OperatorType>(); for (int i = 0; i < TypeMembers.Count; ++i) { var o_a = TypeMembers[i] as OperatorDeclaration; if (o_a == null) { continue; } var o_type = o_a.OperatorType; if (o_type == OperatorType.Equality || o_type == OperatorType.Inequality) { has_equality_or_inequality = true; } if (found_matched.Contains(o_type)) { continue; } var matching_type = o_a.GetMatchingOperator(); if (matching_type == OperatorType.TOP) { continue; } bool pair_found = false; for (int ii = 0; ii < TypeMembers.Count; ++ii) { var o_b = TypeMembers[ii] as OperatorDeclaration; if (o_b == null || o_b.OperatorType != matching_type) { continue; } if (o_a.ResolvedMethod.ReturnType != o_b.ResolvedMethod.ReturnType) { continue; } if (o_a.ResolvedMethod.Parameters != o_b.ResolvedMethod.Parameters) { continue; } found_matched.Add(matching_type); pair_found = true; break; } if (!pair_found) { rc.Report.Error(187, o_a.Location, "The operator `{0}' requires a matching operator `{1}' to also be defined", o_a.GetSignatureForError(), ResolveContext.GetMetadataName(matching_type)); } } }