diff --git a/test/libsolidity/semanticTests/literalSuffixes/suffix_making_pure_external_call.sol b/test/libsolidity/semanticTests/literalSuffixes/suffix_making_pure_external_call.sol new file mode 100644 index 000000000..4c9212cc1 --- /dev/null +++ b/test/libsolidity/semanticTests/literalSuffixes/suffix_making_pure_external_call.sol @@ -0,0 +1,37 @@ +function suffix(int32 x) pure suffix returns (int32) { + return loadNegator().negate(x); +} + +interface INegator { + function negate(int32) external pure returns (int32); +} + +contract Negator is INegator { + function negate(int32 x) external pure override returns (int32) { + return -x; + } +} + +function storeNegator(INegator negator) pure { + assembly { + // this test would also work without assembly if we could hard-code an address here. + mstore(0, negator) + } +} + +function loadNegator() pure returns (INegator negator) { + assembly { + negator := mload(0) + } +} + +contract C { + function testSuffix() public returns (int32) { + storeNegator(new Negator()); + + return 10 suffix; + } +} +// ---- +// testSuffix() -> -10 +// gas legacy: 131793 diff --git a/test/libsolidity/semanticTests/literalSuffixes/suffix_making_view_external_call.sol b/test/libsolidity/semanticTests/literalSuffixes/suffix_making_view_external_call.sol new file mode 100644 index 000000000..2d5082e32 --- /dev/null +++ b/test/libsolidity/semanticTests/literalSuffixes/suffix_making_view_external_call.sol @@ -0,0 +1,41 @@ +function suffix(int32 x) pure suffix returns (int32) { + return loadNegator().negate(x); +} + +interface INegatorPure { + function negate(int32) external pure returns (int32); +} + +interface INegatorView { + function negate(int32) external view returns (int32); +} + +contract Negator is INegatorView { + function negate(int32 x) external view override returns (int32) { + return -x; + } +} + +function storeNegator(INegatorView negator) pure { + assembly { + // this test would also work without assembly if we could hard-code an address here. + mstore(0, negator) + } +} + +function loadNegator() pure returns (INegatorPure negator) { + assembly { + negator := mload(0) + } +} + +contract C { + function testSuffix() public returns (int32) { + storeNegator(new Negator()); + + return 10 suffix; + } +} +// ---- +// testSuffix() -> -10 +// gas legacy: 131793