Allow exponentials with signed base and unsigned power.

This commit is contained in:
krk
2019-09-04 17:32:47 +02:00
committed by chriseth
parent c499758cd8
commit 33f7f960cf
10 changed files with 72 additions and 18 deletions
+11 -8
View File
@@ -600,6 +600,17 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, Type const* _other
else
return nullptr;
}
else if (Token::Exp == _operator)
{
if (auto otherIntType = dynamic_cast<IntegerType const*>(_other))
{
if (otherIntType->isSigned())
return TypeResult::err("Exponentiation power is not allowed to be a signed integer type.");
}
else if (dynamic_cast<FixedPointType const*>(_other))
return nullptr;
return this;
}
auto commonType = Type::commonType(this, _other); //might be an integer or fixed point
if (!commonType)
@@ -610,14 +621,6 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, Type const* _other
return commonType;
if (TokenTraits::isBooleanOp(_operator))
return nullptr;
if (auto intType = dynamic_cast<IntegerType const*>(commonType))
{
if (Token::Exp == _operator && intType->isSigned())
return TypeResult::err("Exponentiation is not allowed for signed integer types.");
}
else if (dynamic_cast<FixedPointType const*>(commonType))
if (Token::Exp == _operator)
return nullptr;
return commonType;
}