Convert properly during storing.

This commit is contained in:
chriseth 2020-11-02 20:53:42 +01:00
parent 1e812e7acc
commit 49bd3f2af4
3 changed files with 10 additions and 2 deletions

View File

@ -2192,8 +2192,9 @@ string YulUtilFunctions::updateStorageValueFunction(
solAssert(_toType.storageBytes() > 0, "Invalid storage bytes size."); solAssert(_toType.storageBytes() > 0, "Invalid storage bytes size.");
return Whiskers(R"( return Whiskers(R"(
function <functionName>(slot, <offset>value) { function <functionName>(slot, <offset><fromValues>) {
sstore(slot, <update>(sload(slot), <offset><prepare>(value))) let <toValues> := <convert>(<fromValues>)
sstore(slot, <update>(sload(slot), <offset><prepare>(<toValues>)))
} }
)") )")
@ -2204,6 +2205,9 @@ string YulUtilFunctions::updateStorageValueFunction(
updateByteSliceFunctionDynamic(_toType.storageBytes()) updateByteSliceFunctionDynamic(_toType.storageBytes())
) )
("offset", _offset.has_value() ? "" : "offset, ") ("offset", _offset.has_value() ? "" : "offset, ")
("convert", conversionFunction(_fromType, _toType))
("fromValues", suffixedVariableNameList("value_", 0, _fromType.sizeOnStack()))
("toValues", suffixedVariableNameList("convertedValue_", 0, _toType.sizeOnStack()))
("prepare", prepareStoreFunction(_toType)) ("prepare", prepareStoreFunction(_toType))
.render(); .render();
} }

View File

@ -17,6 +17,8 @@ contract C {
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// test_store_ok() -> 1 // test_store_ok() -> 1
// x() -> 0 // x() -> 0

View File

@ -18,6 +18,8 @@ contract D {
return (stateBool, stateDecimal, stateBytes); return (stateBool, stateDecimal, stateBytes);
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// stateBool() -> true // stateBool() -> true
// stateBool() -> right(true) // stateBool() -> right(true)