mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Better case expression parsing, better enum errors
This commit is contained in:
parent
ce8899f1a7
commit
322b83d1c6
3 changed files with 25 additions and 10 deletions
|
@ -8246,6 +8246,20 @@ BfTypedValue BfExprEvaluator::CheckEnumCreation(BfAstNode* targetSrc, BfTypeInst
|
||||||
|
|
||||||
if (argValue)
|
if (argValue)
|
||||||
{
|
{
|
||||||
|
if ((argValue.mType->IsRef()) && (argValue.mType->GetUnderlyingType() == resolvedFieldType))
|
||||||
|
{
|
||||||
|
if (auto unaryOperator = BfNodeDynCast<BfUnaryOperatorExpression>(argValues.mResolvedArgs[tupleFieldIdx].mExpression))
|
||||||
|
{
|
||||||
|
mModule->Fail(StrFormat("Invalid use of '%s'. Enum payloads can only be retrieved through 'case' expressions.", BfGetOpName(unaryOperator->mOp)), unaryOperator->mOpToken);
|
||||||
|
argValue = mModule->GetDefaultTypedValue(resolvedFieldType);
|
||||||
|
}
|
||||||
|
else if (auto varDecl = BfNodeDynCast<BfVariableDeclaration>(argValues.mResolvedArgs[tupleFieldIdx].mExpression))
|
||||||
|
{
|
||||||
|
mModule->Fail("Invalid variable declaration. Enum payloads can only be retrieved through 'case' expressions.", varDecl);
|
||||||
|
argValue = mModule->GetDefaultTypedValue(resolvedFieldType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// argValue can have a value even if tuplePtr does not have a value. This can happen if we are assigning to a (void) tuple,
|
// argValue can have a value even if tuplePtr does not have a value. This can happen if we are assigning to a (void) tuple,
|
||||||
// but we have a value that needs to be attempted to be casted to void
|
// but we have a value that needs to be attempted to be casted to void
|
||||||
argValue = mModule->Cast(argValues.mResolvedArgs[tupleFieldIdx].mExpression, argValue, resolvedFieldType, wantConst ? BfCastFlags_WantsConst : BfCastFlags_None);
|
argValue = mModule->Cast(argValues.mResolvedArgs[tupleFieldIdx].mExpression, argValue, resolvedFieldType, wantConst ? BfCastFlags_WantsConst : BfCastFlags_None);
|
||||||
|
|
|
@ -2571,7 +2571,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
|
||||||
}
|
}
|
||||||
if (caseExpr->mCaseExpression == NULL)
|
if (caseExpr->mCaseExpression == NULL)
|
||||||
{
|
{
|
||||||
auto expr = CreateExpressionAfter(caseExpr, (CreateExprFlags)(CreateExprFlags_NoAssignment | CreateExprFlags_PermissiveVariableDecl));
|
auto expr = CreateExpressionAfter(caseExpr, (CreateExprFlags)(CreateExprFlags_NoAssignment | CreateExprFlags_PermissiveVariableDecl | CreateExprFlags_EarlyExit));
|
||||||
if (expr == NULL)
|
if (expr == NULL)
|
||||||
continue;
|
continue;
|
||||||
MEMBER_SET(caseExpr, mCaseExpression, expr);
|
MEMBER_SET(caseExpr, mCaseExpression, expr);
|
||||||
|
|
|
@ -1124,15 +1124,16 @@ bool BfPassInstance::WantsRangeRecorded(BfSourceData* bfSource, int srcIdx, int
|
||||||
if (bfSource == NULL)
|
if (bfSource == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!mErrors.IsEmpty())
|
//TODO: Was this useful, or does 'var' resolution do this better?
|
||||||
{
|
// if (!mErrors.IsEmpty())
|
||||||
// If the last error had a range that was a subset of this one, then just keep the first error
|
// {
|
||||||
// This helps reduce cascading errors to their root cause
|
// // If the last error had a range that was a subset of this one, then just keep the first error
|
||||||
auto lastError = mErrors.back();
|
// // This helps reduce cascading errors to their root cause
|
||||||
if ((lastError->mSource == bfSource) && (isWarning == lastError->mIsWarning) && (isDeferred == lastError->mIsDeferred) &&
|
// auto lastError = mErrors.back();
|
||||||
(lastError->mSrcStart >= srcIdx) && (lastError->mSrcEnd <= srcIdx + srcLen))
|
// if ((lastError->mSource == bfSource) && (isWarning == lastError->mIsWarning) && (isDeferred == lastError->mIsDeferred) &&
|
||||||
return false;
|
// (lastError->mSrcStart >= srcIdx) && (lastError->mSrcEnd <= srcIdx + srcLen))
|
||||||
}
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
// Don't record errors that have already occurred at this location
|
// Don't record errors that have already occurred at this location
|
||||||
BfErrorBase checkError;
|
BfErrorBase checkError;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue