Equality operator allowed for external function types

This commit is contained in:
nishant-sachdeva
2022-01-19 15:20:31 +05:30
parent a07b3ec70f
commit a0d6c11860
11 changed files with 244 additions and 12 deletions
@@ -0,0 +1,17 @@
contract C {
function g() external {}
function comparison_operators_for_external_function_pointers_with_dirty_bits() external returns (bool) {
function() external g_ptr_dirty = this.g;
assembly {
g_ptr_dirty.address := or(g_ptr_dirty.address, shl(160, sub(0,1)))
g_ptr_dirty.selector := or(g_ptr_dirty.selector, shl(32, sub(0,1)))
}
function() external g_ptr = this.g;
return g_ptr == g_ptr_dirty;
}
}
// ====
// compileViaYul: also
// EVMVersion: >=constantinople
// ----
// comparison_operators_for_external_function_pointers_with_dirty_bits() -> true
@@ -0,0 +1,81 @@
contract C {
function f() external {}
function g() external {}
function h() pure external {}
function i() view external {}
function comparison_operators_for_external_functions() public returns (bool) {
assert(
this.f != this.g &&
this.f != this.h &&
this.f != this.i &&
this.g != this.h &&
this.g != this.i &&
this.h != this.i &&
this.f == this.f &&
this.g == this.g &&
this.h == this.h &&
this.i == this.i
);
return true;
}
function comparison_operators_for_local_external_function_pointers() public returns (bool) {
function () external f_local = this.f;
function () external g_local = this.g;
function () external pure h_local = this.h;
function () external view i_local = this.i;
assert(
f_local == this.f &&
g_local == this.g &&
h_local == this.h &&
i_local == this.i &&
f_local != this.g &&
f_local != this.h &&
f_local != this.i &&
g_local != this.f &&
g_local != this.h &&
g_local != this.i &&
h_local != this.f &&
h_local != this.g &&
h_local != this.i &&
i_local != this.f &&
i_local != this.g &&
i_local != this.h
);
assert(
f_local == f_local &&
f_local != g_local &&
f_local != h_local &&
f_local != i_local
);
assert(
g_local == g_local &&
g_local != h_local &&
g_local != i_local
);
assert(
h_local == h_local &&
i_local == i_local &&
h_local != i_local
);
return true;
}
}
// ====
// compileViaYul: also
// ----
// comparison_operators_for_external_functions() -> true
// comparison_operators_for_local_external_function_pointers() -> true
@@ -0,0 +1,12 @@
contract C {
function external_test_function() external {}
function comparison_operator_for_external_function_with_extra_slots() external returns (bool) {
return (
(this.external_test_function{gas: 4} == this.external_test_function) &&
(this.external_test_function{gas: 4} == this.external_test_function{gas: 4})
);
}
}
// ----
// TypeError 2271: (193-259): Operator == not compatible with types function () external and function () external
// TypeError 2271: (277-351): Operator == not compatible with types function () external and function () external
@@ -0,0 +1,23 @@
contract C {
function external_test_function() external {}
function internal_test_function() internal {}
function comparison_operator_between_internal_and_external_function_pointers() external returns (bool) {
function () external external_function_pointer_local = this.external_test_function;
function () internal internal_function_pointer_local = internal_test_function;
assert(
this.external_test_function == external_function_pointer_local &&
internal_function_pointer_local == internal_test_function
);
assert(
internal_function_pointer_local != external_function_pointer_local &&
internal_test_function != this.external_test_function
);
return true;
}
}
// ----
// TypeError 2271: (606-672): Operator != not compatible with types function () and function () external
// TypeError 2271: (688-741): Operator != not compatible with types function () and function () external
@@ -0,0 +1,26 @@
contract C {
function external_test_function1(uint num) external {}
function external_test_function2(bool val) external {}
function comparison_operator_between_internal_and_external_function_pointers() external returns (bool) {
function () external external_function_pointer_local1 = this.external_test_function1;
function () external external_function_pointer_local2 = this.external_test_function2;
assert(
this.external_test_function1 == external_function_pointer_local1 &&
this.external_test_function2 == external_function_pointer_local2
);
assert(
external_function_pointer_local2 != external_function_pointer_local1 &&
this.external_test_function2 != this.external_test_function1
);
return true;
}
}
// ----
// TypeError 9574: (249-333): Type function (uint256) external is not implicitly convertible to expected type function () external.
// TypeError 9574: (343-427): Type function (bool) external is not implicitly convertible to expected type function () external.
// TypeError 2271: (458-522): Operator == not compatible with types function (uint256) external and function () external
// TypeError 2271: (538-602): Operator == not compatible with types function (bool) external and function () external
// TypeError 2271: (726-786): Operator != not compatible with types function (bool) external and function (uint256) external