Skip to content

Commit 8314d2c

Browse files
committed
fix: string concatenation operator dispatches to $IO$string_concat
When the `+` operator is used on String-typed operands, emit a call to the ZRTL `$IO$string_concat` extern instead of a numeric add instruction. Direct string concat (e.g., `println("Hello, " + name)`) and variable assignment now work correctly.
1 parent 9bd1eec commit 8314d2c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

crates/compiler/src/ssa.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,33 @@ impl SsaBuilder {
27062706
)));
27072707
}
27082708

2709+
// String concatenation: "a" + "b" → $IO$string_concat(a, b)
2710+
if matches!(op, FrontendOp::Add)
2711+
&& matches!(
2712+
left_with_type.ty,
2713+
Type::Primitive(zyntax_typed_ast::PrimitiveType::String)
2714+
)
2715+
{
2716+
let left_val = self.translate_expression(block_id, left)?;
2717+
let right_val = self.translate_expression(block_id, right)?;
2718+
let result = self.create_value(
2719+
HirType::Ptr(Box::new(HirType::I8)),
2720+
HirValueKind::Instruction,
2721+
);
2722+
let call_inst = HirInstruction::Call {
2723+
result: Some(result),
2724+
callee: crate::hir::HirCallable::Symbol(
2725+
"$IO$string_concat".to_string(),
2726+
),
2727+
args: vec![left_val, right_val],
2728+
type_args: vec![],
2729+
const_args: vec![],
2730+
is_tail: false,
2731+
};
2732+
self.add_instruction(block_id, call_inst);
2733+
return Ok(result);
2734+
}
2735+
27092736
// Regular binary operations for primitive types
27102737
let left_val = self.translate_expression(block_id, left)?;
27112738
let right_val = self.translate_expression(block_id, right)?;

0 commit comments

Comments
 (0)