Fixed a bug in the handling of dataclass where an existing __eq__ method was being overwritten by a synthesized variant. The same was true for other comparison operators.

This commit is contained in:
Eric Traut 2022-06-27 08:27:26 -07:00
parent 9bad0897c6
commit 6ed0571adf

View File

@ -534,7 +534,10 @@ export function synthesizeDataClassMethods(
hasDeclaredType: true,
});
operatorMethod.details.declaredReturnType = evaluator.getBuiltInObject(node, 'bool');
symbolTable.set(operator, Symbol.createWithType(SymbolFlags.ClassMember, operatorMethod));
// If a method of this name already exists, don't override it.
if (!symbolTable.get(operator)) {
symbolTable.set(operator, Symbol.createWithType(SymbolFlags.ClassMember, operatorMethod));
}
};
// Synthesize comparison operators.