mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-25 19:18:01 +02:00
Add warning to always-true and always-false 'is' checks
This commit is contained in:
parent
00f663f6cc
commit
17e9963d71
1 changed files with 10 additions and 2 deletions
|
@ -11628,6 +11628,14 @@ void BfExprEvaluator::Visit(BfCheckTypeExpression* checkTypeExpr)
|
||||||
if (!matches)
|
if (!matches)
|
||||||
matches = mModule->TypeIsSubTypeOf(typeInstance, targetType->ToTypeInstance());
|
matches = mModule->TypeIsSubTypeOf(typeInstance, targetType->ToTypeInstance());
|
||||||
|
|
||||||
|
if (!typeInstance->IsGenericParam())
|
||||||
|
{
|
||||||
|
if (matches)
|
||||||
|
mModule->Warn(0, "The result of this operation is always 'true'", checkTypeExpr->mIsToken);
|
||||||
|
else
|
||||||
|
mModule->Warn(0, "The result of this operation is always 'false'", checkTypeExpr->mIsToken);
|
||||||
|
}
|
||||||
|
|
||||||
mResult = BfTypedValue(mModule->GetConstValue(matches ? 1 : 0, boolType), boolType);
|
mResult = BfTypedValue(mModule->GetConstValue(matches ? 1 : 0, boolType), boolType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -11664,10 +11672,10 @@ void BfExprEvaluator::Visit(BfCheckTypeExpression* checkTypeExpr)
|
||||||
if ((!wasGenericParamType) && (mModule->mCurMethodState->mMixinState == NULL))
|
if ((!wasGenericParamType) && (mModule->mCurMethodState->mMixinState == NULL))
|
||||||
{
|
{
|
||||||
if (srcTypeInstance == targetType)
|
if (srcTypeInstance == targetType)
|
||||||
mModule->Warn(BfWarning_BF4203_UnnecessaryDynamicCast, StrFormat("Unnecessary cast, the value is already type '%s'",
|
mModule->Warn(BfWarning_BF4203_UnnecessaryDynamicCast, StrFormat("Unnecessary check, the value is already type '%s'",
|
||||||
mModule->TypeToString(srcTypeInstance).c_str()), checkTypeExpr->mIsToken);
|
mModule->TypeToString(srcTypeInstance).c_str()), checkTypeExpr->mIsToken);
|
||||||
else
|
else
|
||||||
mModule->Warn(BfWarning_BF4203_UnnecessaryDynamicCast, StrFormat("Unnecessary cast, '%s' is a subtype of '%s'",
|
mModule->Warn(BfWarning_BF4203_UnnecessaryDynamicCast, StrFormat("Unnecessary check, '%s' is a subtype of '%s'",
|
||||||
mModule->TypeToString(srcTypeInstance).c_str(), mModule->TypeToString(targetType).c_str()), checkTypeExpr->mIsToken);
|
mModule->TypeToString(srcTypeInstance).c_str(), mModule->TypeToString(targetType).c_str()), checkTypeExpr->mIsToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue