mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #14371 from ethereum/overrideMagicType_mobileType
Disallow the use of `MagicType` in complex expressions
This commit is contained in:
commit
2c82873a2c
@ -22,6 +22,7 @@ Compiler Features:
|
||||
|
||||
|
||||
Bugfixes:
|
||||
* Code Generator: Disallow complex expressions whose results are types, built-ins, modules or some unassignable functions. The legacy code generation pipeline would not actually evaluate them, discarding any side-effects they might have.
|
||||
* Code Generator: Fix not entirely deterministic order of functions in unoptimized Yul output. The choice of C++ compiler in some cases would result in different (but equivalent) bytecode (especially from native binaries vs emscripten binaries)
|
||||
* Commandline Interface: Fix internal error when using ``--stop-after parsing`` and requesting some of the outputs that require full analysis or compilation.
|
||||
* Commandline Interface: It is no longer possible to specify both ``--optimize-yul`` and ``--no-optimize-yul`` at the same time.
|
||||
|
@ -1694,6 +1694,8 @@ public:
|
||||
|
||||
Type const* typeArgument() const;
|
||||
|
||||
Type const* mobileType() const override { return nullptr; }
|
||||
|
||||
protected:
|
||||
std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override { return {}; }
|
||||
private:
|
||||
|
@ -0,0 +1,15 @@
|
||||
==== Source: A ====
|
||||
contract C {
|
||||
}
|
||||
==== Source: B ====
|
||||
import "A" as M;
|
||||
|
||||
contract C {
|
||||
function f() public pure returns (bool) {
|
||||
bool flag;
|
||||
((flag = true) ? M : M).C;
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> true
|
@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public pure returns (bool){
|
||||
bool flag;
|
||||
((flag = true) ? (1, 2, 3) : (3, 2, 1));
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> true
|
@ -9,5 +9,5 @@ contract C {
|
||||
// SMTIgnoreOS: macos
|
||||
// SMTIgnoreCex: yes
|
||||
// ----
|
||||
// Warning 6328: (46-71): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (75-113): CHC: Assertion violation happens here.
|
||||
// TypeError 9717: (90-93): Invalid mobile type in true expression.
|
||||
// TypeError 3703: (96-99): Invalid mobile type in false expression.
|
||||
|
@ -0,0 +1,19 @@
|
||||
==== Source: A ====
|
||||
function f() pure returns (uint) {
|
||||
return 42;
|
||||
}
|
||||
==== Source: B ====
|
||||
function f() pure returns (uint) {
|
||||
return 24;
|
||||
}
|
||||
==== Source: C ====
|
||||
import "A" as A;
|
||||
import "B" as B;
|
||||
|
||||
contract C {
|
||||
function f(bool b) public pure returns (uint) {
|
||||
return (b ? A : B).f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 1080: (C:116-125): True expression's type module "A" does not match false expression's type module "B".
|
@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
[(1, 2, 3), (4, 5, 6)];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9656: (47-69): Unable to deduce nameable type for array elements. Try adding explicit type conversion for the first element.
|
@ -4,4 +4,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9656: (47-52): Unable to deduce nameable type for array elements. Try adding explicit type conversion for the first element.
|
||||
// TypeError 9563: (48-51): Invalid mobile type.
|
||||
|
@ -4,4 +4,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9656: (47-56): Unable to deduce nameable type for array elements. Try adding explicit type conversion for the first element.
|
||||
// TypeError 9563: (48-55): Invalid mobile type.
|
||||
|
@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function max(bool isUint) pure public returns (uint8) {
|
||||
return (isUint ? type(uint8) : type(int8)).max;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9717: (98-109): Invalid mobile type in true expression.
|
||||
// TypeError 3703: (112-122): Invalid mobile type in false expression.
|
@ -0,0 +1,16 @@
|
||||
contract A {
|
||||
function f() public {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() public {}
|
||||
}
|
||||
|
||||
contract C {
|
||||
function ab(bool getA) pure public returns (bytes memory) {
|
||||
return (getA ? type(A) : type(B)).runtimeCode;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9717: (186-193): Invalid mobile type in true expression.
|
||||
// TypeError 3703: (196-203): Invalid mobile type in false expression.
|
@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
function max() public pure returns (uint8) {
|
||||
return (type(uint8)).max;
|
||||
}
|
||||
}
|
||||
// ----
|
6
test/libsolidity/syntaxTests/metaTypes/type_max.sol
Normal file
6
test/libsolidity/syntaxTests/metaTypes/type_max.sol
Normal file
@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
function max() public pure returns (uint8) {
|
||||
return type(uint8).max;
|
||||
}
|
||||
}
|
||||
// ----
|
@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function max(bool isUint) public returns (uint8) {
|
||||
return (isUint ? type(uint8) : type(int8)).max;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9717: (93-104): Invalid mobile type in true expression.
|
||||
// TypeError 3703: (107-117): Invalid mobile type in false expression.
|
@ -0,0 +1,9 @@
|
||||
contract A {
|
||||
}
|
||||
|
||||
contract C {
|
||||
function f() public pure returns (bytes memory) {
|
||||
return type(A).runtimeCode;
|
||||
}
|
||||
}
|
||||
// ----
|
@ -0,0 +1,14 @@
|
||||
contract A {
|
||||
}
|
||||
|
||||
contract B {
|
||||
}
|
||||
|
||||
contract C {
|
||||
function f(bool getA) public returns (bytes memory) {
|
||||
return (getA ? type(A) : type(B)).runtimeCode;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9717: (126-133): Invalid mobile type in true expression.
|
||||
// TypeError 3703: (136-143): Invalid mobile type in false expression.
|
Loading…
Reference in New Issue
Block a user