mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Contract level checker: Disallow free function redefinition and alias
shadowing another free function Co-authored-by: chriseth <chris@ethereum.org>
This commit is contained in:
co-authored by
chriseth
parent
1cc0d642e8
commit
e2a2276272
@@ -0,0 +1,19 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
function g() pure returns (uint) { return 42; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g} from "s1.sol";
|
||||
==== Source: s3.sol ====
|
||||
// imports f()->1337 as g()
|
||||
import "s2.sol";
|
||||
// imports f()->1337 as f() and
|
||||
// g()->42 as g
|
||||
import {f as f, g as g} from "s1.sol";
|
||||
contract C {
|
||||
function foo() public pure returns (uint) {
|
||||
// calls f()->1337 / f()->1337
|
||||
return f() / g();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 1686: (s1.sol:0-49): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,19 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
function g() pure returns (uint) { return 42; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g} from "s1.sol";
|
||||
==== Source: s3.sol ====
|
||||
// imports f()->1337 as g()
|
||||
import "s2.sol";
|
||||
// imports f()->1337 as f() and
|
||||
// g()->42 as g
|
||||
import "s1.sol";
|
||||
contract C {
|
||||
function foo() public pure returns (uint) {
|
||||
// calls f()->1337 / f()->1337
|
||||
return f() / g();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 1686: (s1.sol:0-49): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,6 @@
|
||||
==== Source: s1.sol ====
|
||||
import {f as g} from "s2.sol";
|
||||
function f() pure returns (uint) { return 1; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g} from "s1.sol";
|
||||
function f() pure returns (uint) { return 2; }
|
||||
@@ -0,0 +1,7 @@
|
||||
==== Source: s1.sol ====
|
||||
import {f as g, g as h} from "s2.sol";
|
||||
function f() pure returns (uint) { return h() - g(); }
|
||||
==== Source: s2.sol ====
|
||||
import {f as h} from "s1.sol";
|
||||
function f() pure returns (uint) { return 2; }
|
||||
function g() pure returns (uint) { return 4; }
|
||||
@@ -0,0 +1,14 @@
|
||||
==== Source: s1.sol ====
|
||||
import {f as g, g as h} from "s2.sol";
|
||||
function f() pure returns (uint) { return h() - g(); }
|
||||
==== Source: s2.sol ====
|
||||
import {f as h} from "s1.sol";
|
||||
function f() pure returns (uint) { return 2; }
|
||||
function g() pure returns (uint) { return 4; }
|
||||
==== Source: s3.sol ====
|
||||
import "s1.sol";
|
||||
import "s2.sol";
|
||||
// ----
|
||||
// DeclarationError 1686: (s1.sol:39-93): Function with same name and parameter types defined twice.
|
||||
// DeclarationError 1686: (s2.sol:31-77): Function with same name and parameter types defined twice.
|
||||
// DeclarationError 1686: (s2.sol:78-124): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
import {f as g, g as h} from "s2.sol";
|
||||
function f() pure returns (uint) { return h() - g(); }
|
||||
==== Source: s2.sol ====
|
||||
import {f as h} from "s1.sol";
|
||||
function f() pure returns (uint) { return 2; }
|
||||
function g() pure returns (uint) { return 4; }
|
||||
==== Source: s3.sol ====
|
||||
import "s1.sol";
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
import {f as g, g as h} from "s2.sol";
|
||||
function f() pure returns (uint) { return h() - g(); }
|
||||
==== Source: s2.sol ====
|
||||
import {f as h} from "s1.sol";
|
||||
function f() pure returns (uint) { return 2; }
|
||||
function g() pure returns (uint) { return 4; }
|
||||
==== Source: s3.sol ====
|
||||
import "s2.sol";
|
||||
@@ -0,0 +1,10 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as f} from "s1.sol";
|
||||
import {f as f} from "s1.sol";
|
||||
contract C {
|
||||
function g() public pure returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
==== Source: s1.sol ====
|
||||
function f(uint) pure returns (uint) { return 24; }
|
||||
function g() pure returns (bool) { return true; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g, g as g} from "s1.sol";
|
||||
contract C {
|
||||
function foo() public pure returns (uint, bool) {
|
||||
return (g(2), g());
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint16) { return 1337; }
|
||||
function g() pure returns (uint8) { return 42; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g} from "s1.sol";
|
||||
==== Source: s3.sol ====
|
||||
// imports f(uint16)->1337 as g(uint16)
|
||||
import "s2.sol";
|
||||
// imports f(uint16)->1337 as f(uint16) and
|
||||
// g(uint8)->42 as g(uint8)
|
||||
import {f as f, g as g} from "s1.sol";
|
||||
contract C {
|
||||
function foo() public pure returns (uint) {
|
||||
// calls f()->1337 / f()->1337
|
||||
return f() / g();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// DeclarationError 1686: (s1.sol:0-51): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
contract C {}
|
||||
==== Source: s2.sol ====
|
||||
import "s1.sol";
|
||||
function f() pure returns (uint) { return 42; }
|
||||
contract D is C {}
|
||||
// ----
|
||||
// DeclarationError 1686: (s2.sol:17-64): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,12 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
contract C {}
|
||||
==== Source: s2.sol ====
|
||||
import "s1.sol";
|
||||
contract D is C {}
|
||||
==== Source: s3.sol ====
|
||||
import "s2.sol";
|
||||
function f() pure returns (uint) { return 42; }
|
||||
contract E is D {}
|
||||
// ----
|
||||
// DeclarationError 1686: (s3.sol:17-64): Function with same name and parameter types defined twice.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
contract C {
|
||||
function f() public pure virtual returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
==== Source: s2.sol ====
|
||||
import "s1.sol";
|
||||
function f() pure returns (uint) { return 42; }
|
||||
contract D is C {
|
||||
function f() public pure override returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (s1.sol:65-134): This declaration shadows an existing declaration.
|
||||
// Warning 2519: (s2.sol:85-155): This declaration shadows an existing declaration.
|
||||
// DeclarationError 1686: (s2.sol:17-64): Function with same name and parameter types defined twice.
|
||||
@@ -0,0 +1,10 @@
|
||||
==== Source: s1.sol ====
|
||||
contract C {
|
||||
function f() public pure returns (uint) {
|
||||
return 1337;
|
||||
}
|
||||
}
|
||||
==== Source: s2.sol ====
|
||||
import {C.f as g} from "s1.sol";
|
||||
// ----
|
||||
// ParserError 2314: (s2.sol:9-10): Expected '}' but got '.'
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
==== Source: s2.sol ====
|
||||
import "s1.sol";
|
||||
contract C {
|
||||
function g() public pure returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as f, f as f, f as f} from "s1.sol";
|
||||
contract C {
|
||||
function g() public pure returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as g} from "s1.sol";
|
||||
==== Source: s3.sol ====
|
||||
import {g as h} from "s2.sol";
|
||||
contract C {
|
||||
function foo() public pure returns (uint) {
|
||||
return h();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
==== Source: s1.sol ====
|
||||
function f() pure returns (uint) { return 1337; }
|
||||
==== Source: s2.sol ====
|
||||
import {f as f, f as f} from "s1.sol";
|
||||
contract C {
|
||||
function g() public pure returns (uint) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user