1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Soften splat error in BfModule::Cast

This commit is contained in:
Brian Fiete 2023-06-22 06:30:50 -04:00
parent a5a7e6efe0
commit 0c6bf2d6b5
3 changed files with 37 additions and 5 deletions

View file

@ -3536,6 +3536,26 @@ void BfModule::FatalError(const StringImpl& error, const char* file, int line)
BfpSystem_FatalError(fullError.c_str(), "FATAL MODULE ERROR"); BfpSystem_FatalError(fullError.c_str(), "FATAL MODULE ERROR");
} }
void BfModule::InternalError(const StringImpl& error, BfAstNode* refNode, const char* file, int line)
{
String fullError = error;
if (file != NULL)
fullError += StrFormat(" at %s:%d", file, line);
fullError += StrFormat("\nModule: %s", mModuleName.c_str());
if (mCurTypeInstance != NULL)
fullError += StrFormat("\nType: %s", TypeToString(mCurTypeInstance).c_str());
if (mCurMethodInstance != NULL)
fullError += StrFormat("\nMethod: %s", MethodToString(mCurMethodInstance).c_str());
if ((mCurFilePosition.mFileInstance != NULL) && (mCurFilePosition.mFileInstance->mParser != NULL))
fullError += StrFormat("\nSource Location: %s:%d", mCurFilePosition.mFileInstance->mParser->mFileName.c_str(), mCurFilePosition.mCurLine + 1);
Fail(String("INTERNAL ERROR: ") + fullError, refNode);
}
void BfModule::NotImpl(BfAstNode* astNode) void BfModule::NotImpl(BfAstNode* astNode)
{ {
Fail("INTERNAL ERROR: Not implemented", astNode); Fail("INTERNAL ERROR: Not implemented", astNode);
@ -23579,11 +23599,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
auto typeDef = typeInstance->mTypeDef; auto typeDef = typeInstance->mTypeDef;
auto methodDef = mCurMethodInstance->mMethodDef; auto methodDef = mCurMethodInstance->mMethodDef;
BF_ASSERT(methodDef->mName != "__ASSERTNAME"); if (methodDef->mName.StartsWith('_'))
if (methodDef->mName == "__FATALERRORNAME") {
BFMODULE_FATAL(this, "__FATALERRORNAME"); BF_ASSERT(methodDef->mName != "__ASSERTNAME");
if (methodDef->mName == "__STACKOVERFLOW") if (methodDef->mName == "__FATALERRORNAME")
StackOverflow(); BFMODULE_FATAL(this, "__FATALERRORNAME");
if (methodDef->mName == "__STACKOVERFLOW")
StackOverflow();
if (methodDef->mName == "__INTERNALERROR")
InternalError("Bad method name", methodDef->GetRefNode());
}
if (typeInstance->IsClosure()) if (typeInstance->IsClosure())
{ {

View file

@ -1605,6 +1605,7 @@ public:
public: public:
void FatalError(const StringImpl& error, const char* file = NULL, int line = -1); void FatalError(const StringImpl& error, const char* file = NULL, int line = -1);
void InternalError(const StringImpl& error, BfAstNode* refNode = NULL, const char* file = NULL, int line = -1);
void NotImpl(BfAstNode* astNode); void NotImpl(BfAstNode* astNode);
void AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); void AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None);
bool CheckProtection(BfProtection protection, BfTypeDef* checkType, bool allowProtected, bool allowPrivate); bool CheckProtection(BfProtection protection, BfTypeDef* checkType, bool allowProtected, bool allowPrivate);

View file

@ -14857,6 +14857,12 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf
{ {
if (typedVal.IsSplat()) if (typedVal.IsSplat())
{ {
if ((!toStructTypeInstance->IsSplattable()) && (toStructTypeInstance->mInstSize != 0))
{
InternalError("typedVal.IsSplat(), but !toStructTypeInstance->IsSplattable() && toStructTypeInstance->mInstSize != 0", srcNode);
return GetDefaultTypedValue(toType, true, BfDefaultValueKind_Addr);
}
BF_ASSERT(toStructTypeInstance->IsSplattable() || (toStructTypeInstance->mInstSize == 0)); BF_ASSERT(toStructTypeInstance->IsSplattable() || (toStructTypeInstance->mInstSize == 0));
return BfTypedValue(typedVal.mValue, toStructTypeInstance, typedVal.IsThis() ? BfTypedValueKind_ThisSplatHead : BfTypedValueKind_SplatHead); return BfTypedValue(typedVal.mValue, toStructTypeInstance, typedVal.IsThis() ? BfTypedValueKind_ThisSplatHead : BfTypedValueKind_SplatHead);
} }