From 92dc80ad6616f1fef72cfef1ae120e4fb5b41146 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 24 Oct 2026 18:04:52 +0000 Subject: feat(operator): select operator overloads by the expected result type Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/ControlFlowGen.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/ControlFlowGen.cc') diff --git a/lib/CodeGen/ControlFlowGen.cc b/lib/CodeGen/ControlFlowGen.cc index a351162..fe9a954 100644 --- a/lib/CodeGen/ControlFlowGen.cc +++ b/lib/CodeGen/ControlFlowGen.cc @@ -229,7 +229,12 @@ void CodeGen::emitCaseStmt(CaseStmtAST *Stmt) { } if (containsString(LabelType) && (LabelConverted || !isObjectLValue(Label))) materializeOperatorReceiver(LabelValue, LabelType); - auto Overload = resolveOperator(Op, LeftType, LabelType); + ResultContext BoolContext{resolveType("BOOLEAN"), true}; + auto Overload = resolveOperator(Op, LeftType, LabelType, &BoolContext); + if (Overload.WrongResult) { + reportError("CASE comparison must return BOOLEAN"); + return nullptr; + } if (Overload.Signature && !Overload.Ambiguous) { const TypeInfo *Result = resolveType(Overload.Signature->ReturnTypeName); if (!Result || Result->Kind != TypeKind::Boolean) { @@ -237,7 +242,8 @@ void CodeGen::emitCaseStmt(CaseStmtAST *Stmt) { return nullptr; } } - Value *Result = emitBinaryOp(Op, LeftValue, LeftType, LabelValue, LabelType, Branch.Line); + Value *Result = emitBinaryOp(Op, LeftValue, LeftType, LabelValue, LabelType, Branch.Line, + &BoolContext); cleanupTemporaries(Temporaries); return Result; }; -- cgit v1.3.1-4-g156e