Merge pull request #8872 from ethereum/int-min-max

implemented type(X).min and type(X).max for all integer types
This commit is contained in:
chriseth
2020-05-11 15:08:19 +02:00
committed by GitHub
24 changed files with 705 additions and 34 deletions
+24 -8
View File
@@ -220,18 +220,29 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
return {};
}
TypePointer firstArgType = type(*arguments.front());
if (
firstArgType->category() != Type::Category::TypeType ||
dynamic_cast<TypeType const&>(*firstArgType).actualType()->category() != TypeType::Category::Contract
)
bool wrongType = false;
if (firstArgType->category() == Type::Category::TypeType)
{
TypeType const* typeTypePtr = dynamic_cast<TypeType const*>(firstArgType);
Type::Category typeCategory = typeTypePtr->actualType()->category();
if (
typeCategory != Type::Category::Contract &&
typeCategory != Type::Category::Integer
)
wrongType = true;
}
else
wrongType = true;
if (wrongType)
{
m_errorReporter.typeError(
4259_error,
arguments.front()->location(),
"Invalid type for argument in function call. "
"Contract type required, but " +
type(*arguments.front())->toString(true) +
" provided."
"Invalid type for argument in the function call. "
"A contract type or an integer type is required, but " +
type(*arguments.front())->toString(true) + " provided."
);
return {};
}
@@ -2688,6 +2699,11 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
annotation.isPure = true;
else if (magicType->kind() == MagicType::Kind::MetaType && memberName == "interfaceId")
annotation.isPure = true;
else if (
magicType->kind() == MagicType::Kind::MetaType &&
(memberName == "min" || memberName == "max")
)
annotation.isPure = true;
}
return false;