aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ControlFlowGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-24 18:04:52 +0000
committer_ov4 <ov4@ov4.org>2026-10-24 18:06:18 +0000
commit92dc80ad6616f1fef72cfef1ae120e4fb5b41146 (patch)
tree37cb449eaa832739ede6fe8bdc280aa995394882 /lib/CodeGen/ControlFlowGen.cc
parent0900667401415a0914b8a1510543c7c7eaf32e53 (diff)
feat(operator): select operator overloads by the expected result type
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/ControlFlowGen.cc')
-rw-r--r--lib/CodeGen/ControlFlowGen.cc10
1 files changed, 8 insertions, 2 deletions
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;
};