From 44bd9cf595ed954970589ccd1fb31c873bab29d3 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:02:00 +0200 Subject: [PATCH] Fix const enum type check --- oscar64/Declaration.cpp | 4 ++-- oscar64/Parser.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 0b1cd0f..e1fee98 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -639,9 +639,9 @@ bool Declaration::IsSubType(const Declaration* dec) const return true; else if (mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_VOID) return true; - else if (mType == DT_TYPE_STRUCT) + else if (mType == DT_TYPE_STRUCT || mType == DT_TYPE_ENUM) return mScope == dec->mScope || (mIdent == dec->mIdent && mSize == dec->mSize); - else if (mType == DT_TYPE_STRUCT || mType == DT_TYPE_ENUM || mType == DT_TYPE_UNION) + else if (mType == DT_TYPE_UNION) return false; else if (mType == DT_TYPE_ARRAY) return mSize <= dec->mSize && mBase->IsSubType(dec->mBase); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 7f1c86a..289fde6 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -277,6 +277,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags) dec = new Declaration(mScanner->mLocation, DT_TYPE_ENUM); dec->mFlags = flags; dec->mSize = 1; + dec->mScope = new DeclarationScope(nullptr); mScanner->NextToken(); if (mScanner->mToken == TK_IDENT) @@ -635,7 +636,10 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex dec->mOffset = offset; } else + { + dtype->CanAssign(exp->mDecType); mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Incompatible constant initializer"); + } } else mErrors->Error(exp->mLocation, EERR_CONSTANT_INITIALIZER, "Constant initializer expected");