From 9f834c4232579abc62bb83740561fc4f85e76d96 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 18 Jan 2025 10:13:29 +0100 Subject: [PATCH] Fix integer type coercion with cast operator --- oscar64/Parser.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 280b864..6a719cd 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -7457,6 +7457,13 @@ Expression* Parser::CoerceExpression(Expression* exp, Declaration* type) { while (fexp && !fexp->mBase->mBase->IsSame(type)) fexp = fexp->mNext; + if (!fexp && type->mType == DT_TYPE_INTEGER) + { + fexp = tdec->mScope->Lookup(Ident::Unique("(cast)")); + while (fexp && !fexp->mBase->mBase->IsSame(TheSignedIntTypeDeclaration)) + fexp = fexp->mNext; + } + if (fexp) { Expression* aexp = new Expression(exp->mLocation, EX_PREFIX); @@ -7734,6 +7741,9 @@ Expression* Parser::ParsePostfixExpression(bool lhs) } else if (exp->mDecType->mType == DT_TYPE_ARRAY || exp->mDecType->mType == DT_TYPE_POINTER) { + if (!nexp->mRight->mDecType->IsIntegerType()) + nexp->mRight = CoerceExpression(nexp->mRight, TheSignedIntTypeDeclaration); + nexp->mDecType = exp->mDecType->mBase; } else