Merge pull request #5807 from ethereum/fixed_point_encoding

Return TypeError is fixed point encoding is attempted.
This commit is contained in:
chriseth 2019-01-17 23:47:07 +01:00 committed by GitHub
commit 0b14d7a2d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 1 deletions

View File

@ -8,6 +8,7 @@ Compiler Features:
Bugfixes:
* TypeChecker: Return type error if fixed point encoding is attempted instead of throwing ``UnimplementedFeatureError``.
* Yul: Check that arguments to ``dataoffset`` and ``datasize`` are literals at parse time and properly take this into account in the optimizer.
* Yul: Parse number literals for detecting duplicate switch cases.
* Yul: Require switch cases to have the same type.

View File

@ -1482,7 +1482,16 @@ void TypeChecker::typeCheckABIEncodeFunctions(
if (argType->category() == Type::Category::RationalNumber)
{
if (!argType->mobileType())
auto const& rationalType = dynamic_cast<RationalNumberType const&>(*argType);
if (rationalType.isFractional())
{
m_errorReporter.typeError(
arguments[i]->location(),
"Fractional numbers cannot yet be encoded."
);
continue;
}
else if (!argType->mobileType())
{
m_errorReporter.typeError(
arguments[i]->location(),

View File

@ -0,0 +1,7 @@
contract C {
function f1() public pure returns (bytes memory) {
return abi.encode(0.1, 1);
}
}
// ----
// TypeError: (92-95): Fractional numbers cannot yet be encoded.

View File

@ -0,0 +1,9 @@
pragma experimental ABIEncoderV2;
contract C {
function f1() public pure returns (bytes memory) {
return abi.encode(0.1, 1);
}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// TypeError: (126-129): Fractional numbers cannot yet be encoded.

View File

@ -0,0 +1,8 @@
contract C {
function f1() public pure returns (bytes memory) {
return abi.encodePacked(0.1, 1);
}
}
// ----
// TypeError: (98-101): Fractional numbers cannot yet be encoded.
// TypeError: (103-104): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.

View File

@ -0,0 +1,10 @@
pragma experimental ABIEncoderV2;
contract C {
function f1() public pure returns (bytes memory) {
return abi.encodePacked(0.1, 1);
}
}
// ----
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
// TypeError: (132-135): Fractional numbers cannot yet be encoded.
// TypeError: (137-138): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.