mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2920 from ethereum/fixConstantBytes
Allow constant byte arrays.
This commit is contained in:
commit
1fc71bd758
@ -18,6 +18,7 @@ Features:
|
||||
Bugfixes:
|
||||
* ABI JSON: Include all overloaded events.
|
||||
* Parser: Crash fix related to parseTypeName.
|
||||
* Type Checker: Allow constant byte arrays.
|
||||
|
||||
### 0.4.16 (2017-08-24)
|
||||
|
||||
|
@ -623,7 +623,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
{
|
||||
bool allowed = false;
|
||||
if (auto arrayType = dynamic_cast<ArrayType const*>(_variable.type().get()))
|
||||
allowed = arrayType->isString();
|
||||
allowed = arrayType->isByteArray();
|
||||
if (!allowed)
|
||||
m_errorReporter.typeError(_variable.location(), "Constants of non-value type not yet implemented.");
|
||||
}
|
||||
|
@ -10076,6 +10076,30 @@ BOOST_AUTO_TEST_CASE(function_types_sig)
|
||||
BOOST_CHECK(callContractFunction("h()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constant_string)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
bytes constant a = "\x03\x01\x02";
|
||||
bytes constant b = hex"030102";
|
||||
string constant c = "hello";
|
||||
function f() returns (bytes) {
|
||||
return a;
|
||||
}
|
||||
function g() returns (bytes) {
|
||||
return b;
|
||||
}
|
||||
function h() returns (bytes) {
|
||||
return bytes(c);
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
BOOST_CHECK(callContractFunction("f()") == encodeDyn(string("\x03\x01\x02")));
|
||||
BOOST_CHECK(callContractFunction("g()") == encodeDyn(string("\x03\x01\x02")));
|
||||
BOOST_CHECK(callContractFunction("h()") == encodeDyn(string("hello")));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -2385,6 +2385,18 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars)
|
||||
CHECK_ERROR(text, TypeError, "implemented");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment_to_const_string_bytes)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
bytes constant a = "\x00\x01\x02";
|
||||
bytes constant b = hex"000102";
|
||||
string constant c = "hello";
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constant_struct)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user