def visit_op_expr(self, e: OpExpr) -> None: super().visit_op_expr(e) if e.op in ['and', 'or']: target = self.get_type(e) e.left = self.coerce(e.left, target, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, target, self.get_type(e.right), self.type_context()) else: method_type = e.method_type if self.dynamic_funcs[-1] or isinstance(method_type, AnyType): e.left = self.coerce_to_dynamic(e.left, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, AnyType(), self.get_type(e.right), self.type_context()) elif method_type: method_callable = cast(Callable, method_type) operand = e.right # For 'in', the order of operands is reversed. if e.op == 'in': operand = e.left # TODO arg_types[0] may not be reliable operand = self.coerce(operand, method_callable.arg_types[0], self.get_type(operand), self.type_context()) if e.op == 'in': e.left = operand else: e.right = operand
def visit_op_expr(self, e: OpExpr) -> None: super().visit_op_expr(e) if e.op in ["and", "or"]: target = self.get_type(e) e.left = self.coerce(e.left, target, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, target, self.get_type(e.right), self.type_context()) else: method_type = e.method_type if self.dynamic_funcs[-1] or isinstance(method_type, AnyType): e.left = self.coerce_to_dynamic(e.left, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, AnyType(), self.get_type(e.right), self.type_context()) elif method_type: method_callable = cast(Callable, method_type) operand = e.right # For 'in', the order of operands is reversed. if e.op == "in": operand = e.left # TODO arg_types[0] may not be reliable operand = self.coerce( operand, method_callable.arg_types[0], self.get_type(operand), self.type_context() ) if e.op == "in": e.left = operand else: e.right = operand
def visit_op_expr(self, e: OpExpr) -> None: super().visit_op_expr(e) if e.op in ['and', 'or']: target = self.get_type(e) e.left = self.coerce(e.left, target, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, target, self.get_type(e.right), self.type_context()) else: method_type = e.method_type if self.dynamic_funcs[-1] or isinstance(method_type, AnyType): e.left = self.coerce_to_dynamic(e.left, self.get_type(e.left), self.type_context()) e.right = self.coerce(e.right, AnyType(), self.get_type(e.right), self.type_context()) elif method_type: method_callable = cast(Callable, method_type) operand = e.right # TODO arg_types[0] may not be reliable operand = self.coerce(operand, method_callable.arg_types[0], self.get_type(operand), self.type_context()) e.right = operand