mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Free functions.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {}
|
||||
}
|
||||
function fun() {
|
||||
C.f();
|
||||
}
|
||||
// ----
|
||||
// TypeError 3419: (68-73): Cannot call function via contract type name.
|
||||
@@ -0,0 +1,3 @@
|
||||
constructor() {}
|
||||
// ----
|
||||
// ParserError 7858: (0-11): Expected pragma, import directive or contract/interface/library/struct/enum/function definition.
|
||||
@@ -0,0 +1,3 @@
|
||||
fallback(){}
|
||||
// ----
|
||||
// ParserError 7858: (0-8): Expected pragma, import directive or contract/interface/library/struct/enum/function definition.
|
||||
@@ -0,0 +1,4 @@
|
||||
function fun() someModifier {
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7576: (15-27): Undeclared identifier.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
modifier someModifier() { _; }
|
||||
}
|
||||
|
||||
function fun() C.someModifier {
|
||||
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (65-66): Expected '{' but got '.'
|
||||
@@ -0,0 +1,9 @@
|
||||
function f() {}
|
||||
contract C {
|
||||
function f() public {}
|
||||
function g() public {
|
||||
f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (31-53): This declaration shadows an existing declaration.
|
||||
@@ -0,0 +1,5 @@
|
||||
function fun1() public { }
|
||||
function fun2() internal { }
|
||||
// ----
|
||||
// SyntaxError 4126: (0-26): Free functions cannot have visibility.
|
||||
// SyntaxError 4126: (27-55): Free functions cannot have visibility.
|
||||
@@ -0,0 +1,3 @@
|
||||
function f();
|
||||
// ----
|
||||
// TypeError 4668: (0-13): Free functions must be implemented.
|
||||
@@ -0,0 +1,4 @@
|
||||
function fun(uint256, uint[] calldata _x, uint[] storage _y) view returns (uint, uint[] calldata) {
|
||||
return (_y[0], _x);
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,8 @@
|
||||
function f() {
|
||||
uint x = 2;
|
||||
x;
|
||||
}
|
||||
function g(uint[] storage x) pure { x[0] = 1; }
|
||||
// ----
|
||||
// Warning 2018: (0-39): Function state mutability can be restricted to pure
|
||||
// TypeError 8961: (76-80): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
|
||||
@@ -0,0 +1,9 @@
|
||||
function f(uint) returns (bytes memory) {}
|
||||
function f(uint[] memory x) returns (bytes memory) { return f(x[0]); }
|
||||
function g(uint8) {}
|
||||
function g(uint16) {}
|
||||
function t() {
|
||||
g(2);
|
||||
}
|
||||
// ----
|
||||
// TypeError 4487: (176-177): No unique declaration found after argument-dependent lookup.
|
||||
@@ -0,0 +1,4 @@
|
||||
function fun() override {
|
||||
}
|
||||
// ----
|
||||
// SyntaxError 1750: (0-27): Free functions cannot override.
|
||||
@@ -0,0 +1,4 @@
|
||||
function fun() payable {
|
||||
}
|
||||
// ----
|
||||
// TypeError 9559: (0-26): Free functions cannot be payable.
|
||||
@@ -0,0 +1,3 @@
|
||||
receive() {}
|
||||
// ----
|
||||
// ParserError 7858: (0-7): Expected pragma, import directive or contract/interface/library/struct/enum/function definition.
|
||||
@@ -0,0 +1,4 @@
|
||||
struct S { uint x; }
|
||||
function fun(S storage) {
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,4 @@
|
||||
function fun() virtual {
|
||||
}
|
||||
// ----
|
||||
// SyntaxError 4493: (0-26): Free functions cannot be virtual.
|
||||
@@ -0,0 +1,4 @@
|
||||
contract C {}
|
||||
function C() {}
|
||||
// ----
|
||||
// DeclarationError 2333: (14-29): Identifier already declared.
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
struct S { uint x; }
|
||||
}
|
||||
function f() returns (uint) { S storage t; }
|
||||
// ----
|
||||
// DeclarationError 7920: (70-71): Identifier not found or not unique.
|
||||
@@ -0,0 +1,6 @@
|
||||
function fun() {
|
||||
fun{gas: 1}();
|
||||
fun{value: 1}();
|
||||
}
|
||||
// ----
|
||||
// TypeError 2193: (21-32): Function call options can only be set on external function calls or contract creations.
|
||||
@@ -0,0 +1,7 @@
|
||||
function f() returns (uint) { C.S storage t; t.x; }
|
||||
|
||||
contract C {
|
||||
struct S { uint x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 3464: (45-46): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
|
||||
@@ -0,0 +1,3 @@
|
||||
function f(S storage g) view returns (uint) { S storage t = g; return t.x; }
|
||||
struct S { uint x; }
|
||||
// ----
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {}
|
||||
function f() {
|
||||
super;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7576: (33-38): Undeclared identifier. "super" is not (or not yet) visible at this point.
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {}
|
||||
function f() {
|
||||
this;
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 7576: (33-37): Undeclared identifier. "this" is not (or not yet) visible at this point.
|
||||
@@ -0,0 +1,14 @@
|
||||
==== Source: a ====
|
||||
function f(uint x) pure returns (uint) { return x * 3; }
|
||||
==== Source: b ====
|
||||
import "a" as A;
|
||||
function g(uint x) pure returns (uint) { return A.f(x) * 3; }
|
||||
==== Source: c ====
|
||||
import "b" as B;
|
||||
contract C {
|
||||
function f() public pure {
|
||||
B.g(2);
|
||||
B.A.f(3);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
Reference in New Issue
Block a user