codegen: shorten the overflow checking when converting into enums

This commit is contained in:
Yoichi Hirai 2016-11-09 14:14:18 +01:00
parent effca18250
commit 0a6c937dcb
No known key found for this signature in database
GPG Key ID: E7B75D080FCF7992

View File

@ -661,7 +661,8 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
if (targetTypeCategory == Type::Category::Enum) if (targetTypeCategory == Type::Category::Enum)
{ {
EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType); EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
m_context << u256(enumType.numberOfMembers()) << Instruction::DUP2 << Instruction::LT << Instruction::ISZERO; solAssert(enumType.numberOfMembers() > 0, "empty enum should have caused a parser error.");
m_context << u256(enumType.numberOfMembers() - 1) << Instruction::DUP2 << Instruction::GT;
m_context.appendConditionalJumpTo(m_context.errorTag()); m_context.appendConditionalJumpTo(m_context.errorTag());
} }
} }