mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3875 from ethereum/constructorSelfRef
Stricter check for "this" in constructor.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public pure {}
|
||||
constructor() public {
|
||||
C c = this;
|
||||
c.f(); // this does not warn now, but should warn in the future
|
||||
this.f();
|
||||
(this).f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (172-176): "this" used in constructor. Note that external functions of a contract cannot be called while it is being constructed.
|
||||
// Warning: (191-195): "this" used in constructor. Note that external functions of a contract cannot be called while it is being constructed.
|
||||
@@ -0,0 +1,28 @@
|
||||
contract A {
|
||||
function a() public pure {
|
||||
}
|
||||
}
|
||||
contract B {
|
||||
constructor(address) public {
|
||||
}
|
||||
function b(address) public returns (A) {
|
||||
return new A();
|
||||
}
|
||||
}
|
||||
contract C {
|
||||
B m_b;
|
||||
C m_c;
|
||||
constructor(C other_c) public {
|
||||
m_c = other_c;
|
||||
m_b = new B(this);
|
||||
m_b.b(this).a();
|
||||
g(this).f();
|
||||
other_c.f();
|
||||
m_c.f();
|
||||
}
|
||||
function f() public pure {
|
||||
}
|
||||
function g(C) public view returns (C) {
|
||||
return m_c;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
contract A {
|
||||
function x() pure internal {}
|
||||
}
|
||||
|
||||
contract B is A {
|
||||
constructor() public {
|
||||
// used to trigger warning about using ``this`` in constructor
|
||||
super.x();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user