From a3e37a9d5aa2039255783ffba4629574c4acf4c6 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 6 Nov 2018 13:22:33 +0100 Subject: Relax identity requirement of function type conversions during code generation. --- libsolidity/codegen/CompilerUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index d89d023e..22f97dfa 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1014,6 +1014,8 @@ void CompilerUtils::convertType( // stack:
m_context << Instruction::POP; } + else if (stackTypeCategory == Type::Category::Function && targetTypeCategory == Type::Category::Function) + solAssert(_typeOnStack.isImplicitlyConvertibleTo(_targetType), "Invalid function type conversion requested."); else { // All other types should not be convertible to non-equal types. -- cgit v1.2.3 From b16a3644fe7d54ed5fa6d7a7dac40b4aab641e76 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 6 Nov 2018 13:29:49 +0100 Subject: Function type conversion test cases. --- libsolidity/codegen/CompilerUtils.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 22f97dfa..90eb74fe 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1014,12 +1014,24 @@ void CompilerUtils::convertType( // stack:
m_context << Instruction::POP; } - else if (stackTypeCategory == Type::Category::Function && targetTypeCategory == Type::Category::Function) - solAssert(_typeOnStack.isImplicitlyConvertibleTo(_targetType), "Invalid function type conversion requested."); else { - // All other types should not be convertible to non-equal types. - solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); + if (stackTypeCategory == Type::Category::Function && targetTypeCategory == Type::Category::Function) + { + FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); + FunctionType const& targetType = dynamic_cast(_targetType); + solAssert( + typeOnStack.isImplicitlyConvertibleTo(targetType) && + typeOnStack.sizeOnStack() == targetType.sizeOnStack() && + (typeOnStack.kind() == FunctionType::Kind::Internal || typeOnStack.kind() == FunctionType::Kind::External) && + typeOnStack.kind() == targetType.kind(), + "Invalid function type conversion requested." + ); + } + else + // All other types should not be convertible to non-equal types. + solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); + if (_cleanupNeeded && _targetType.canBeStored() && _targetType.storageBytes() < 32) m_context << ((u256(1) << (8 * _targetType.storageBytes())) - 1) -- cgit v1.2.3