Solidity has come out with major breaking release of the Solidity compiler and language i.e. v0.6.0.

As a smart contract developer and Blockchain Enthusiast, one should be aware about them as it is going to change the way we develop smart contracts. These changes are basically inspired by existing languages and introduced to make things more explicit, and developer friendly. I am listing some of them with sample here:

Inheritance

Virtual & override keyword

Base functions can be overridden by marking them as `virtual`. The overriding function must then use the `override` keyword in the function header. For multiple inheritance, you have to specify all base contracts that define the same function and have not yet been overridden by another base contract.

pragma solidity >=0.5.0 <0.7.0;



contract Base1

{

function foo() virtual public {}

}



contract Base2

{

function foo() virtual public {}

}



contract Inherited is Base1, Base2

{

// Derives from multiple bases defining foo(), so we must explicitly

// override it

function foo() public override(Base1, Base2) {}

}

Abstract contract

Contracts need to be marked as `abstract` when at least one of their functions is not implemented. If a contract inherits from an abstract contract and does not implement all non-implemented functions by overriding, it needs to be marked as abstract as well.Contracts may be marked as abstract even though all functions are implemented.

pragma solidity ^0.6.0; abstract contract Feline { function utterance() public virtual returns (bytes32); } contract Cat is Feline { function utterance() public override returns (bytes32) {

return "miaow";

} }

Array

.length member

Member-access to length of arrays is now always read-only, even for storage arrays. It is no longer possible to resize storage arrays assigning a new value to their length.

Array.length = 5 // Incorrect

Array.length++ // Incorrect array.push() // Correct

array.push(value) // Correct

Array Slices

Array slices are a view on a contiguous portion of an array. They are written as `x[start:end]`, where start and end are expressions resulting in a uint256 type (or implicitly convertible to it). The first element of the slice is x[start] and the last element is x[end - 1].

If start is greater than end or if end is greater than the length of the array, an exception is thrown.

Both start and end are optional: start defaults to 0 and end defaults to the length of the array.

As of now, array slices are only implemented for calldata arrays.

/// Forward call to "setOwner(address)" that is implemented by client

/// after doing basic validation on the address argument.

function forward(bytes calldata _payload) external {

bytes4 sig = abi.decode(_payload[:4], (bytes4));

if (sig == bytes4(keccak256("setOwner(address)"))) {

address owner = abi.decode(_payload[4:], (address));

require(owner != address(0), "Address of owner cannot be zero.");

}

(bool status,) = client.delegatecall(_payload);

require(status, "Forwarded call failed.");

}

Fallback

Traditional split up into a new fallback function that is defined using the fallback keyword and a receive ether function defined using the receive keyword. These both functions cannot have arguments, cannot return anything and must have external visibility

Receive Ether Function

It is executed on plain Ether transfers (e.g. via .send() or .transfer()). If no such function exists, but a payable fallback function exists, the fallback function will be called on a plain Ether transfer. If neither a receive Ether nor a payable fallback function is present, the contract cannot receive Ether through regular transactions and throws an exception.

Fallback Function

It is executed on a call to the contract if none of the other functions match the given function signature, or if no data was supplied at all and there is no receive Ether function. The fallback function always receives data, but in order to also receive Ether it must be marked payable.

pragma solidity ^0.6.0;



contract Test {

// This function is called for all messages sent to

// this contract (there is no other function).

// Sending Ether to this contract will cause an exception,

// because the fallback function does not have the `payable`

// modifier.

fallback() external { x = 1; }

uint x;

}



contract TestPayable {

// This function is called for all messages sent to

// this contract, except plain Ether transfers

// (there is no other function except the receive function).

// Any call with non-empty calldata to this contract will execute

// the fallback function (even if Ether is sent along with the call).

fallback() external payable { x = 1; y = msg.value; }



// This function is called for plain Ether transfers, i.e.

// for every call with empty calldata.

receive() external payable { x = 2; y = msg.value; }

uint x;

uint y;

}

Exception handling

try/catch

Solidity now supports exception handling in the form of try/catch-statements, but only for external function calls and contract creation calls. Errors inside the expression are not caught, only a revert happening inside the external call itself. There is very limited and conditional support for this feature for now. For more detail, see this documentation.

pragma solidity ^0.6.0;



interface DataFeed { function getData(address token) external returns (uint value); }



contract FeedConsumer {

DataFeed feed;

uint errorCount;

function rate(address token) public returns (uint value, bool success) {

// Permanently disable the mechanism if there are

// more than 10 errors.

require(errorCount < 10);

try feed.getData(token) returns (uint v) {

return (v, true);

} catch Error(string memory /*reason*/) {

// This is executed in case

// revert was called inside getData

// and a reason string was provided.

errorCount++;

return (0, false);

} catch (bytes memory /*lowLevelData*/) {

// This is executed in case revert() was used

// or there was a failing assertion, division

// by zero, etc. inside getData.

errorCount++;

return (0, false);

}

}

}

File Level Declaration

`struct` and `enum` types can be declared at file level now.

pragma solidity ^0.6.0; enum Status {Added, Removed} struct Employee {

uint256 id;

string name;

Status s;

} contract NameRegister {

mapping(uint256 => Employee) public nameReg;



function add(uint256 id, string memory name) public {

nameReg[id] = Employee(id, name, Status.Added);

}

} contract SalaryRegister {

mapping(uint256 => Employee) public salaryReg;



function add(uint256 id, string memory name) public {

salaryReg[id] = Employee(id, name, Status.Added);

}

}

References:

For complete changelog: https://github.com/ethereum/solidity/releases/tag/v0.6.0

For documentation of all breaking changes: https://solidity.readthedocs.io/en/latest/060-breaking-changes.html