mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #960 from Denton-L/change-else-style
Change else style
This commit is contained in:
commit
18abafe029
@ -45,8 +45,7 @@ become the new richest.
|
|||||||
richest = msg.sender;
|
richest = msg.sender;
|
||||||
mostSent = msg.value;
|
mostSent = msg.value;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,8 +57,7 @@ become the new richest.
|
|||||||
pendingWithdrawals[msg.sender] = 0;
|
pendingWithdrawals[msg.sender] = 0;
|
||||||
if (msg.sender.send(amount)) {
|
if (msg.sender.send(amount)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pendingWithdrawals[msg.sender] = amount;
|
pendingWithdrawals[msg.sender] = amount;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -90,8 +88,7 @@ This is as opposed to the more intuitive sending pattern.
|
|||||||
richest = msg.sender;
|
richest = msg.sender;
|
||||||
mostSent = msg.value;
|
mostSent = msg.value;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,8 +275,7 @@ As a result, the following code is legal, despite being poorly written::
|
|||||||
uint bar = 5;
|
uint bar = 5;
|
||||||
if (true) {
|
if (true) {
|
||||||
bar += baz;
|
bar += baz;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
uint baz = 10;// never executes
|
uint baz = 10;// never executes
|
||||||
}
|
}
|
||||||
return bar;// returns 5
|
return bar;// returns 5
|
||||||
|
@ -461,16 +461,17 @@ If you do not want to throw, you can return a pair::
|
|||||||
|
|
||||||
function getCounter(uint index)
|
function getCounter(uint index)
|
||||||
returns (uint counter, bool error) {
|
returns (uint counter, bool error) {
|
||||||
if (index >= counters.length) return (0, true);
|
if (index >= counters.length)
|
||||||
else return (counters[index], false);
|
return (0, true);
|
||||||
|
else
|
||||||
|
return (counters[index], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCounter(uint index) {
|
function checkCounter(uint index) {
|
||||||
var (counter, error) = getCounter(index);
|
var (counter, error) = getCounter(index);
|
||||||
if (error) {
|
if (error) {
|
||||||
...
|
...
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,8 +133,7 @@ of votes.
|
|||||||
// If the delegate already voted,
|
// If the delegate already voted,
|
||||||
// directly add to the number of votes
|
// directly add to the number of votes
|
||||||
proposals[delegate.vote].voteCount += sender.weight;
|
proposals[delegate.vote].voteCount += sender.weight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// If the delegate did not vote yet,
|
// If the delegate did not vote yet,
|
||||||
// add to her weight.
|
// add to her weight.
|
||||||
delegate.weight += sender.weight;
|
delegate.weight += sender.weight;
|
||||||
|
@ -273,17 +273,17 @@ No::
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
For ``if`` blocks which have an ``else`` or ``else if`` clause, the ``else`` should be
|
For ``if`` blocks which have an ``else`` or ``else if`` clause, the ``else`` should be
|
||||||
placed on it's own line following the previous closing parenthesis. The
|
placed on the same line as the ``if``'s closing brace. This is an exception compared
|
||||||
parenthesis for the else block should follow the same rules as the other
|
to the rules of other block-like structures.
|
||||||
conditional control structures.
|
|
||||||
|
|
||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
if (x < 3) {
|
if (x < 3) {
|
||||||
x += 1;
|
x += 1;
|
||||||
}
|
} else if (x > 7) {
|
||||||
else {
|
|
||||||
x -= 1;
|
x -= 1;
|
||||||
|
} else {
|
||||||
|
x = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -296,7 +296,8 @@ No::
|
|||||||
|
|
||||||
if (x < 3) {
|
if (x < 3) {
|
||||||
x += 1;
|
x += 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
x -= 1;
|
x -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ contract StandardToken is Token {
|
|||||||
balanceOf[_to] += _value;
|
balanceOf[_to] += _value;
|
||||||
Transfer(msg.sender, _to, _value);
|
Transfer(msg.sender, _to, _value);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,8 +28,7 @@ contract StandardToken is Token {
|
|||||||
balanceOf[_to] += _value;
|
balanceOf[_to] += _value;
|
||||||
Transfer(_from, _to, _value);
|
Transfer(_from, _to, _value);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,9 +130,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
|
|||||||
if (previousOwner != 0) {
|
if (previousOwner != 0) {
|
||||||
if (!record.owner.send(auction.sumOfBids - auction.highestBid / 100))
|
if (!record.owner.send(auction.sumOfBids - auction.highestBid / 100))
|
||||||
throw;
|
throw;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!auction.highestBidder.send(auction.highestBid - auction.secondHighestBid))
|
if (!auction.highestBidder.send(auction.highestBid - auction.secondHighestBid))
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
@ -147,9 +145,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
|
|||||||
if (now < m_toRecord[_name].renewalDate)
|
if (now < m_toRecord[_name].renewalDate)
|
||||||
throw;
|
throw;
|
||||||
bid(_name, msg.sender, msg.value);
|
bid(_name, msg.sender, msg.value);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Record record = m_toRecord[_name];
|
Record record = m_toRecord[_name];
|
||||||
if (record.owner != 0)
|
if (record.owner != 0)
|
||||||
throw;
|
throw;
|
||||||
|
@ -2563,8 +2563,9 @@ BOOST_AUTO_TEST_CASE(event)
|
|||||||
if (_manually) {
|
if (_manually) {
|
||||||
bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f;
|
bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f;
|
||||||
log3(bytes32(msg.value), s, bytes32(msg.sender), _id);
|
log3(bytes32(msg.value), s, bytes32(msg.sender), _id);
|
||||||
} else
|
} else {
|
||||||
Deposit(msg.sender, _id, msg.value);
|
Deposit(msg.sender, _id, msg.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
@ -540,7 +540,7 @@ BOOST_AUTO_TEST_CASE(if_statement)
|
|||||||
{
|
{
|
||||||
char const* text = "contract test {\n"
|
char const* text = "contract test {\n"
|
||||||
" function fun(uint256 a) {\n"
|
" function fun(uint256 a) {\n"
|
||||||
" if (a >= 8) return 2; else { var b = 7; }\n"
|
" if (a >= 8) { return 2; } else { var b = 7; }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
BOOST_CHECK(successParse(text));
|
BOOST_CHECK(successParse(text));
|
||||||
|
Loading…
Reference in New Issue
Block a user