From 20c2ca39922f4230b504888644d04f4bc8d6b8f3 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 9 Nov 2016 17:02:25 +0100 Subject: [PATCH] ast, codegen: disallow conversion between different enum types --- Changelog.md | 1 + libsolidity/ast/Types.cpp | 2 +- libsolidity/codegen/CompilerUtils.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4bed85ea9..851f39a01 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Features: Bugfixes: * Parser: disallow empty enum definitions. + * Type checker: disallow conversion between different enum types. ### 0.4.4 (2016-10-31) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index a134a0bba..f09953931 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1585,7 +1585,7 @@ size_t EnumType::numberOfMembers() const bool EnumType::isExplicitlyConvertibleTo(Type const& _convertTo) const { - return _convertTo.category() == category() || _convertTo.category() == Category::Integer; + return _convertTo == *this || _convertTo.category() == Category::Integer; } unsigned EnumType::memberValue(ASTString const& _member) const diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ad155b13f..2f30f53ed 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -348,7 +348,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp } break; case Type::Category::Enum: - solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Enum, ""); + solAssert(_targetType == _typeOnStack || targetTypeCategory == Type::Category::Integer, ""); break; case Type::Category::FixedPoint: solAssert(false, "Not yet implemented - FixedPointType.");