From df900c558396ed4a33905eea730964a4ecc087ea Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 10:18:51 +0200 Subject: [PATCH 1/3] test: add a test about using an inherited enum definition as an expression, with an explicit mention of the base contract. The test is about #1131. --- test/libsolidity/SolidityEndToEndTest.cpp | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 16002f9a7..bb197cca9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5905,6 +5905,48 @@ BOOST_AUTO_TEST_CASE(using_library_structs) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7), u256(8))); } +BOOST_AUTO_TEST_CASE(library_struct_as_an_expression) +{ + char const* sourceCode = R"( + library Arst { + struct Foo { + int Things; + int Stuff; + } + } + + contract Tsra { + function f() returns(uint) { + Arst.Foo; + return 1; + } + } + )"; + compileAndRun(sourceCode, 0, "Tsra"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1))); +} + +BOOST_AUTO_TEST_CASE(library_enum_as_an_expression) +{ + char const* sourceCode = R"( + library Arst { + enum Foo { + Things, + Stuff + } + } + + contract Tsra { + function f() returns(uint) { + Arst.Foo; + return 1; + } + } + )"; + compileAndRun(sourceCode, 0, "Tsra"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1))); +} + BOOST_AUTO_TEST_CASE(short_strings) { // This test verifies that the byte array encoding that combines length and data works From 7cee39fc17a94bb14ccf60dee6209162e21a7b97 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 10:05:36 +0200 Subject: [PATCH 2/3] codegen: skip contract L for L.Foo where Foo is a type Fixes #1116 --- libsolidity/codegen/ExpressionCompiler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3d05edd3b..da3e56cc1 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -861,11 +861,12 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) } // Special processing for TypeType because we do not want to visit the library itself - // for internal functions. + // for internal functions, or enum/struct definitions. if (TypeType const* type = dynamic_cast(_memberAccess.expression().annotation().type.get())) { if (dynamic_cast(type->actualType().get())) { + solAssert(_memberAccess.annotation().type, "_memberAccess has no type"); if (auto funType = dynamic_cast(_memberAccess.annotation().type.get())) { if (funType->location() != FunctionType::Location::Internal) @@ -883,6 +884,10 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) m_context << m_context.functionEntryLabel(*function).pushTag(); } } + else if (dynamic_cast(_memberAccess.annotation().type.get())) + { + // no-op + } else _memberAccess.expression().accept(*this); } From abf393126ba7e5da7871dc87276f36af6568f4fd Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 10:21:21 +0200 Subject: [PATCH 3/3] Changelog: add a comment about fixing #1116 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 44f3183b5..833c617d2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ Bugfixes: * Type checker: Proper type checking for bound functions. * Type checker: fix crash related to invalid fixed point constants * Code generator: expect zero stack increase after ``super`` as an expression. + * Code Generator: fixed an internal compiler error for ``L.Foo`` for ``enum Foo`` defined in library ``L``. * Inline assembly: support the ``address`` opcode. * Inline assembly: fix parsing of assignment after a label. * Inline assembly: external variables of unsupported type (such as ``this``, ``super``, etc.)