Skip to content

Commit bd5dc64

Browse files
committed
fix: use Type::Any for binary/unary op results instead of hardcoded I32
The parser was hardcoding binary and unary operation results as I32, which broke operator overloading for opaque types. Now using Type::Any to let the type checker infer the correct result type from trait impls.
1 parent 90d0660 commit bd5dc64

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

crates/zyn_peg/src/runtime.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,10 @@ impl AstHostFunctions for TypedAstBuilder {
16561656
let right_expr = self.get_expr(right).unwrap_or_else(|| self.inner.int_literal(0, span));
16571657

16581658
let binary_op = Self::string_to_binary_op(op);
1659-
let result_type = Type::Primitive(PrimitiveType::I32);
1659+
1660+
// Don't hardcode result type - let type checker infer it from operands
1661+
// For operator overloading, the result type depends on the trait implementation
1662+
let result_type = Type::Any;
16601663

16611664
let expr = self.inner.binary(binary_op, left_expr, right_expr, result_type, span);
16621665
self.store_expr(expr)
@@ -1675,7 +1678,10 @@ impl AstHostFunctions for TypedAstBuilder {
16751678
}
16761679

16771680
let unary_op = Self::string_to_unary_op(op);
1678-
let result_type = Type::Primitive(PrimitiveType::I32);
1681+
1682+
// Don't hardcode result type - let type checker infer it from operand
1683+
// For operator overloading, the result type depends on the trait implementation
1684+
let result_type = Type::Any;
16791685

16801686
let expr = self.inner.unary(unary_op, operand_expr, result_type, span);
16811687
self.store_expr(expr)

0 commit comments

Comments
 (0)