mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix bugs in example contracts
This commit is contained in:
parent
b2fcd59ee6
commit
41e5b2c3c2
@ -213,6 +213,8 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
|
||||
|
||||
::
|
||||
|
||||
// This will not compile
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract C {
|
||||
@ -545,9 +547,11 @@ Please ensure you test your fallback function thoroughly to ensure the execution
|
||||
test.call(0xabcdef01); // hash does not exist
|
||||
// results in test.x becoming == 1.
|
||||
|
||||
// The following call will fail, reject the
|
||||
// Ether and return false:
|
||||
test.send(2 ether);
|
||||
// The following will not compile, but even
|
||||
// if someone sends ether to that contract,
|
||||
// the transaction will fail and reject the
|
||||
// Ether.
|
||||
//test.send(2 ether);
|
||||
}
|
||||
}
|
||||
|
||||
@ -773,13 +777,17 @@ seen in the following example::
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract owned {
|
||||
function owned() { owner = msg.sender; }
|
||||
address owner;
|
||||
}
|
||||
|
||||
contract mortal is owned {
|
||||
function kill() {
|
||||
if (msg.sender == owner) selfdestruct(owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract Base1 is mortal {
|
||||
function kill() { /* do cleanup 1 */ mortal.kill(); }
|
||||
}
|
||||
@ -800,6 +808,11 @@ derived override, but this function will bypass
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract owned {
|
||||
function owned() { owner = msg.sender; }
|
||||
address owner;
|
||||
}
|
||||
|
||||
contract mortal is owned {
|
||||
function kill() {
|
||||
if (msg.sender == owner) selfdestruct(owner);
|
||||
@ -879,6 +892,8 @@ error "Linearization of inheritance graph impossible".
|
||||
|
||||
::
|
||||
|
||||
// This will not compile
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract X {}
|
||||
@ -914,10 +929,16 @@ Contract functions can lack an implementation as in the following example (note
|
||||
function utterance() returns (bytes32);
|
||||
}
|
||||
|
||||
Such contracts cannot be compiled (even if they contain implemented functions alongside non-implemented functions), but they can be used as base contracts::
|
||||
Such contracts cannot be compiled (even if they contain
|
||||
implemented functions alongside non-implemented functions),
|
||||
but they can be used as base contracts::
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract Feline {
|
||||
function utterance() returns (bytes32);
|
||||
}
|
||||
|
||||
contract Cat is Feline {
|
||||
function utterance() returns (bytes32) { return "miaow"; }
|
||||
}
|
||||
|
@ -181,7 +181,9 @@ parameters from the function declaration, but can be in arbitrary order.
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract C {
|
||||
function f(uint key, uint value) { ... }
|
||||
function f(uint key, uint value) {
|
||||
// ...
|
||||
}
|
||||
|
||||
function g() {
|
||||
// named arguments
|
||||
@ -323,6 +325,8 @@ This happens because Solidity inherits its scoping rules from JavaScript.
|
||||
This is in contrast to many languages where variables are only scoped where they are declared until the end of the semantic block.
|
||||
As a result, the following code is illegal and cause the compiler to throw an error, ``Identifier already declared``::
|
||||
|
||||
// This will not compile
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract ScopingErrors {
|
||||
|
@ -179,11 +179,13 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like
|
||||
}
|
||||
}
|
||||
|
||||
Now someone tricks you into sending ether to the address of this attack wallet:
|
||||
Now someone tricks you into sending ether to the address of this attack wallet::
|
||||
|
||||
::
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
interface TxUserWallet {
|
||||
function transferTo(address dest, uint amount);
|
||||
}
|
||||
|
||||
contract TxAttackWallet {
|
||||
address owner;
|
||||
|
@ -376,7 +376,7 @@ Example that shows how to use internal function types::
|
||||
function (uint, uint) returns (uint) f
|
||||
)
|
||||
internal
|
||||
returns (uint)
|
||||
returns (uint r)
|
||||
{
|
||||
r = self[0];
|
||||
for (uint i = 1; i < self.length; i++) {
|
||||
@ -599,6 +599,8 @@ possible:
|
||||
|
||||
::
|
||||
|
||||
// This will not compile.
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract C {
|
||||
@ -606,6 +608,7 @@ possible:
|
||||
// The next line creates a type error because uint[3] memory
|
||||
// cannot be converted to uint[] memory.
|
||||
uint[] x = [uint(1), 3, 4];
|
||||
}
|
||||
}
|
||||
|
||||
It is planned to remove this restriction in the future but currently creates
|
||||
@ -812,8 +815,9 @@ for each ``_KeyType``, recursively.
|
||||
}
|
||||
|
||||
contract MappingUser {
|
||||
address contractAddress = 0x42;
|
||||
function f() returns (uint) {
|
||||
return MappingExample(<address>).balances(this);
|
||||
return MappingExample(contractAddress).balances(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user