mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Updates after code review
This commit is contained in:
parent
7b81a65bc6
commit
cdbc06419f
@ -3874,7 +3874,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
|||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
9921_error,
|
9921_error,
|
||||||
_usingFor.location(),
|
_usingFor.location(),
|
||||||
"The \"using\" directive cannot be used to bind functions to enum types."
|
"The \"using\" directive cannot be used to bind function to enum type as an operator."
|
||||||
);
|
);
|
||||||
|
|
||||||
Type const* normalizedType = TypeProvider::withLocationIfReference(
|
Type const* normalizedType = TypeProvider::withLocationIfReference(
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
type Int is int16;
|
||||||
|
|
||||||
|
using {keccak256 as +} for Int;
|
||||||
|
|
||||||
|
function keccak256(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) + Int.unwrap(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public returns (Int) {
|
||||||
|
return Int.wrap(3) + Int.wrap(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// test() -> 7
|
@ -0,0 +1,30 @@
|
|||||||
|
==== Source: s1.sol ====
|
||||||
|
type Int is int;
|
||||||
|
|
||||||
|
using {add as +} for Int global;
|
||||||
|
using {add as +} for Int;
|
||||||
|
|
||||||
|
function add(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) + Int.unwrap(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_add() pure returns (Int) {
|
||||||
|
return Int.wrap(1) + Int.wrap(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
==== Source: s2.sol ====
|
||||||
|
import "s1.sol";
|
||||||
|
|
||||||
|
contract C2 {
|
||||||
|
function test1() pure public returns (Int) {
|
||||||
|
return test_add();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test2() pure public returns (Int) {
|
||||||
|
return Int.wrap(3) + Int.wrap(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// test1() -> 3
|
||||||
|
// test2() -> 7
|
@ -0,0 +1,26 @@
|
|||||||
|
type Int is int16;
|
||||||
|
|
||||||
|
using {unsub as -} for Int global;
|
||||||
|
using {sub as -} for Int;
|
||||||
|
|
||||||
|
function sub(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) - Int.unwrap(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
function unsub(Int a) pure returns (Int) {
|
||||||
|
return Int.wrap(-Int.unwrap(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test_sub() public returns (Int) {
|
||||||
|
return Int.wrap(7) - Int.wrap(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_unsub() public returns (Int) {
|
||||||
|
return -Int.wrap(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// test_sub() -> 5
|
||||||
|
// test_unsub() -> -4
|
@ -0,0 +1,8 @@
|
|||||||
|
type Int is int16;
|
||||||
|
|
||||||
|
using {IntError as +} for Int;
|
||||||
|
|
||||||
|
error IntError(Int a, Int b);
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError 8187: (27-35): Expected function name.
|
@ -1,8 +1,10 @@
|
|||||||
type Int is int16;
|
type Int is int16;
|
||||||
|
|
||||||
using {IntError as +} for Int;
|
using {C.IntEvent as +} for Int;
|
||||||
|
|
||||||
error IntError(Int a, Int b);
|
contract C {
|
||||||
|
event IntEvent(Int a, Int b);
|
||||||
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 8187: (27-35): Expected function name.
|
// TypeError 8187: (27-37): Expected function name.
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
type Int is int16;
|
||||||
|
|
||||||
|
using {keccak256 as +} for Int;
|
||||||
|
|
||||||
|
function keccak256(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// Warning 2319: (53-128): This declaration shadows a builtin symbol.
|
@ -0,0 +1,24 @@
|
|||||||
|
==== Source: Int.sol ====
|
||||||
|
type Int is int;
|
||||||
|
|
||||||
|
using {add as +} for Int global;
|
||||||
|
|
||||||
|
function add(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
==== Source: test.sol ====
|
||||||
|
import "Int.sol";
|
||||||
|
|
||||||
|
using {another_add as +} for Int;
|
||||||
|
|
||||||
|
function another_add(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() pure returns (Int) {
|
||||||
|
return Int.wrap(0) + Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError 2271: (test.sol:181-206): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator.
|
@ -1,12 +0,0 @@
|
|||||||
type Int is int16;
|
|
||||||
|
|
||||||
using {f as +} for IntError;
|
|
||||||
|
|
||||||
error IntError();
|
|
||||||
|
|
||||||
function f(Int _a, Int _b) pure returns (Int) {
|
|
||||||
return Int.wrap(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----
|
|
||||||
// TypeError 5172: (39-47): Name has to refer to a user-defined value type, struct, enum or contract.
|
|
@ -0,0 +1,42 @@
|
|||||||
|
struct S {
|
||||||
|
uint8 a;
|
||||||
|
}
|
||||||
|
|
||||||
|
using {add as +,
|
||||||
|
sub as -,
|
||||||
|
mul as *} for S;
|
||||||
|
|
||||||
|
function add(S memory a, S memory) pure returns (S memory) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub(S calldata a, S calldata) pure returns (S calldata) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(S storage a, S storage) pure returns (S storage) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
S s;
|
||||||
|
function test(S calldata c) public {
|
||||||
|
S memory m;
|
||||||
|
|
||||||
|
c + c; // calldata to memory
|
||||||
|
s + s; // storage to memory
|
||||||
|
|
||||||
|
m - m; // memory to calldata
|
||||||
|
s - s; // storage to calldata
|
||||||
|
|
||||||
|
c * c; // calldata to storage
|
||||||
|
m * m; // memory to storage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 2271: (421-426): Binary operator + not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found.
|
||||||
|
// TypeError 2271: (458-463): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
||||||
|
// TypeError 2271: (495-500): Binary operator - not compatible with types struct S memory and struct S memory. No matching user-defined operator found.
|
||||||
|
// TypeError 2271: (532-537): Binary operator - not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
||||||
|
// TypeError 2271: (571-576): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found.
|
||||||
|
// TypeError 2271: (609-614): Binary operator * not compatible with types struct S memory and struct S memory. No matching user-defined operator found.
|
@ -16,9 +16,10 @@ contract C {
|
|||||||
S s;
|
S s;
|
||||||
|
|
||||||
function test() public {
|
function test() public {
|
||||||
S memory sTmp;
|
S storage sTmp;
|
||||||
|
S memory tmp;
|
||||||
s + s;
|
s + s;
|
||||||
sTmp + true;
|
tmp + true;
|
||||||
true + s;
|
true + s;
|
||||||
-sTmp;
|
-sTmp;
|
||||||
-s;
|
-s;
|
||||||
@ -27,8 +28,9 @@ contract C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 2271: (288-293): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
// TypeError 2271: (311-316): Binary operator + not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
||||||
// TypeError 5653: (303-314): User defined binary operator + not compatible with types struct S memory and bool.
|
// TypeError 5653: (326-336): User defined binary operator + not compatible with types struct S memory and bool.
|
||||||
// TypeError 2271: (324-332): Binary operator + not compatible with types bool and struct S storage ref.
|
// TypeError 2271: (346-354): Binary operator + not compatible with types bool and struct S storage ref.
|
||||||
// TypeError 4907: (357-359): Unary operator - cannot be applied to type struct S storage ref. No matching user-defined operator found.
|
// TypeError 4907: (364-369): Unary operator - cannot be applied to type struct S storage pointer. No matching user-defined operator found.
|
||||||
// TypeError 4907: (369-374): Unary operator - cannot be applied to type bool.
|
// TypeError 4907: (379-381): Unary operator - cannot be applied to type struct S storage ref. No matching user-defined operator found.
|
||||||
|
// TypeError 4907: (391-396): Unary operator - cannot be applied to type bool.
|
||||||
|
@ -10,7 +10,7 @@ function another_add(Int, Int) pure returns (Int) {
|
|||||||
return Int.wrap(0);
|
return Int.wrap(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract C {
|
contract B {
|
||||||
using {another_add as +} for Int;
|
using {another_add as +} for Int;
|
||||||
|
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -18,5 +18,11 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contract C is B {
|
||||||
|
function g() public {
|
||||||
|
Int.wrap(0) + Int.wrap(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 2271: (281-306): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator.
|
// TypeError 2271: (281-306): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator.
|
||||||
|
@ -10,4 +10,4 @@ function add(E, E) pure returns (E) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// TypeError 9921: (0-23): The "using" directive cannot be used to bind functions to enum types.
|
// TypeError 9921: (0-23): The "using" directive cannot be used to bind function to enum type as an operator.
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
using {add as +} for C.Event;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
event Event();
|
||||||
|
}
|
||||||
|
|
||||||
|
function add(C.Event, C.Event) pure returns (C.Event) {}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError 5172: (21-28): Name has to refer to a user-defined value type, struct, enum or contract.
|
@ -47,7 +47,7 @@ function bitnot(S calldata) pure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test(S calldata s) pure {
|
function test(S calldata s) pure {
|
||||||
s + s;
|
s + s; // OK
|
||||||
s - s;
|
s - s;
|
||||||
s * s;
|
s * s;
|
||||||
s / s;
|
s / s;
|
||||||
@ -64,5 +64,5 @@ function test(S calldata s) pure {
|
|||||||
// TypeError 7617: (82-87): The function "unsub" needs to have one or two parameters of type S and the same data location to be used for the operator -.
|
// TypeError 7617: (82-87): The function "unsub" needs to have one or two parameters of type S and the same data location to be used for the operator -.
|
||||||
// TypeError 3605: (82-87): The function "unsub" needs to have parameters and return value of the same type to be used for the operator -.
|
// TypeError 3605: (82-87): The function "unsub" needs to have parameters and return value of the same type to be used for the operator -.
|
||||||
// TypeError 7743: (98-104): The function "bitnot" needs to return exactly one value of type S to be used for the operator ~.
|
// TypeError 7743: (98-104): The function "bitnot" needs to return exactly one value of type S to be used for the operator ~.
|
||||||
// TypeError 2271: (758-763): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found.
|
// TypeError 2271: (764-769): Binary operator * not compatible with types struct S calldata and struct S calldata. No matching user-defined operator found.
|
||||||
// TypeError 4907: (791-793): Unary operator - cannot be applied to type struct S calldata. No matching user-defined operator found.
|
// TypeError 4907: (797-799): Unary operator - cannot be applied to type struct S calldata. No matching user-defined operator found.
|
||||||
|
@ -43,7 +43,7 @@ contract C {
|
|||||||
S b;
|
S b;
|
||||||
|
|
||||||
function test() public view {
|
function test() public view {
|
||||||
a + b;
|
a + b; // OK
|
||||||
a - b;
|
a - b;
|
||||||
a * b;
|
a * b;
|
||||||
a / b;
|
a / b;
|
||||||
@ -59,5 +59,5 @@ contract C {
|
|||||||
// TypeError 7743: (68-71): The function "mod" needs to return exactly one value of type S to be used for the operator %.
|
// TypeError 7743: (68-71): The function "mod" needs to return exactly one value of type S to be used for the operator %.
|
||||||
// TypeError 7743: (82-87): The function "unsub" needs to return exactly one value of type S to be used for the operator -.
|
// TypeError 7743: (82-87): The function "unsub" needs to return exactly one value of type S to be used for the operator -.
|
||||||
// TypeError 1147: (98-104): The function "bitnot" needs to have exactly one parameter of type S to be used for the operator ~.
|
// TypeError 1147: (98-104): The function "bitnot" needs to have exactly one parameter of type S to be used for the operator ~.
|
||||||
// TypeError 2271: (722-727): Binary operator * not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
// TypeError 2271: (728-733): Binary operator * not compatible with types struct S storage ref and struct S storage ref. No matching user-defined operator found.
|
||||||
// TypeError 4907: (779-781): Unary operator ~ cannot be applied to type struct S storage ref. No matching user-defined operator found.
|
// TypeError 4907: (785-787): Unary operator ~ cannot be applied to type struct S storage ref. No matching user-defined operator found.
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
type Int is int16;
|
||||||
|
|
||||||
|
function add(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
using {add as +} for Int global;
|
||||||
|
|
||||||
|
function test() pure public {
|
||||||
|
Int.wrap(0) + Int.wrap(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// SyntaxError 3367: (108-140): "global" can only be used at file level.
|
@ -0,0 +1,20 @@
|
|||||||
|
==== Source: s1.sol ====
|
||||||
|
type Int is int;
|
||||||
|
|
||||||
|
using {add as +} for Int global;
|
||||||
|
using {another_add as +} for Int;
|
||||||
|
|
||||||
|
function add(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function another_add(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() pure returns (Int) {
|
||||||
|
return Int.wrap(1) + Int.wrap(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError 2271: (s1.sol:284-309): Binary operator + not compatible with types Int and Int. Multiple user-defined functions provided for this operator.
|
@ -0,0 +1,15 @@
|
|||||||
|
type Int is int;
|
||||||
|
|
||||||
|
using {unsub as -} for Int global;
|
||||||
|
using {another_unsub as -} for Int;
|
||||||
|
|
||||||
|
function unsub(Int) pure returns (Int) {}
|
||||||
|
|
||||||
|
function another_unsub(Int) pure returns (Int) {}
|
||||||
|
|
||||||
|
function test() pure returns (Int) {
|
||||||
|
return -Int.wrap(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError 4907: (232-244): Built-in unary operator - cannot be applied to type Int. Multiple user-defined functions provided for this operator.
|
@ -1,15 +1,23 @@
|
|||||||
==== Source: s1.sol ====
|
==== Source: s1.sol ====
|
||||||
type Int is int;
|
type Int is int;
|
||||||
using {add as +} for Int global;
|
using {add as +} for Int global;
|
||||||
|
using {sub as -} for Int;
|
||||||
|
|
||||||
function add(Int, Int) pure returns (Int) {
|
function add(Int, Int) pure returns (Int) {
|
||||||
return Int.wrap(3);
|
return Int.wrap(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sub(Int, Int) pure returns (Int) {
|
||||||
|
return Int.wrap(4);
|
||||||
|
}
|
||||||
|
|
||||||
==== Source: s2.sol ====
|
==== Source: s2.sol ====
|
||||||
import "s1.sol";
|
import "s1.sol";
|
||||||
contract C {
|
contract C {
|
||||||
function f() pure public {
|
function f() pure public {
|
||||||
Int.wrap(0) + Int.wrap(0);
|
Int.wrap(0) + Int.wrap(0);
|
||||||
|
Int.wrap(0) - Int.wrap(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 2271: (s2.sol:104-129): Binary operator - not compatible with types Int and Int. No matching user-defined operator found.
|
||||||
|
Loading…
Reference in New Issue
Block a user