diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | docs/050-breaking-changes.rst | 2 | ||||
-rw-r--r-- | docs/abi-spec.rst | 6 | ||||
-rw-r--r-- | docs/assembly.rst | 10 | ||||
-rw-r--r-- | docs/common-patterns.rst | 12 | ||||
-rw-r--r-- | docs/contracts.rst | 61 | ||||
-rw-r--r-- | docs/control-structures.rst | 24 | ||||
-rw-r--r-- | docs/frequently-asked-questions.rst | 12 | ||||
-rw-r--r-- | docs/introduction-to-smart-contracts.rst | 4 | ||||
-rw-r--r-- | docs/layout-of-source-files.rst | 15 | ||||
-rw-r--r-- | docs/miscellaneous.rst | 2 | ||||
-rw-r--r-- | docs/security-considerations.rst | 10 | ||||
-rw-r--r-- | docs/solidity-by-example.rst | 10 | ||||
-rw-r--r-- | docs/structure-of-a-contract.rst | 12 | ||||
-rw-r--r-- | docs/style-guide.rst | 28 | ||||
-rw-r--r-- | docs/types.rst | 72 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rwxr-xr-x | test/cmdlineTests.sh | 2 | ||||
-rw-r--r-- | test/contracts/AuctionRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/FixedFeeRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/Wallet.cpp | 2 | ||||
-rwxr-xr-x | test/externalTests.sh | 4 |
22 files changed, 174 insertions, 122 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 20b4d97b..f2c84d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(EthPolicy) eth_policy() # project name and version should be set after cmake_policy CMP0048 -set(PROJECT_VERSION "0.4.26") +set(PROJECT_VERSION "0.5.0") project(solidity VERSION ${PROJECT_VERSION}) option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" OFF) diff --git a/docs/050-breaking-changes.rst b/docs/050-breaking-changes.rst index 5a7add5d..51864571 100644 --- a/docs/050-breaking-changes.rst +++ b/docs/050-breaking-changes.rst @@ -327,7 +327,7 @@ New version: :: - pragma solidity >0.4.25; + pragma solidity >0.4.99 <0.6.0; contract OtherContract { uint x; diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst index 69d253d7..7c9d9f9e 100644 --- a/docs/abi-spec.rst +++ b/docs/abi-spec.rst @@ -211,7 +211,7 @@ Given the contract: :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract Foo { function bar(bytes3[2] memory) public pure {} @@ -468,7 +468,7 @@ For example, :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract Test { constructor() public { b = hex"12345678901234567890123456789012"; } @@ -515,7 +515,7 @@ As an example, the code :: - pragma solidity ^0.4.19; + pragma solidity >=0.4.19 <0.6.0; pragma experimental ABIEncoderV2; contract Test { diff --git a/docs/assembly.rst b/docs/assembly.rst index 90bfa1f1..5d723645 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -67,7 +67,7 @@ idea is that assembly libraries will be used to enhance the Solidity language. .. code:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; library GetCode { function at(address _addr) public view returns (bytes memory o_code) { @@ -92,7 +92,7 @@ efficient code, for example: .. code:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; library VectorSum { // This function is less efficient because the optimizer currently fails to @@ -381,7 +381,7 @@ Local Solidity variables are available for assignments, for example: .. code:: - pragma solidity ^0.4.11; + pragma solidity >=0.4.11 <0.6.0; contract C { uint b; @@ -420,7 +420,7 @@ be just ``0``, but it can also be a complex functional-style expression. .. code:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f(uint x) public view returns (uint b) { @@ -685,7 +685,7 @@ Example: We will follow an example compilation from Solidity to assembly. We consider the runtime bytecode of the following Solidity program:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f(uint x) public pure returns (uint y) { diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index d26e4377..84c18936 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -13,11 +13,11 @@ Withdrawal from Contracts The recommended method of sending funds after an effect is using the withdrawal pattern. Although the most intuitive method of sending Ether, as a result of an effect, is a -direct ``send`` call, this is not recommended as it +direct ``transfer`` call, this is not recommended as it introduces a potential security risk. You may read more about this on the :ref:`security_considerations` page. -This is an example of the withdrawal pattern in practice in +The following is an example of the withdrawal pattern in practice in a contract where the goal is to send the most money to the contract in order to become the "richest", inspired by `King of the Ether <https://www.kingoftheether.com/>`_. @@ -28,7 +28,7 @@ become the new richest. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract WithdrawalContract { address public richest; @@ -65,7 +65,7 @@ This is as opposed to the more intuitive sending pattern: :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract SendContract { address payable public richest; @@ -130,7 +130,7 @@ restrictions highly readable. :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract AccessRestriction { // These will be assigned at the construction @@ -282,7 +282,7 @@ function finishes. :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract StateMachine { enum Stages { diff --git a/docs/contracts.rst b/docs/contracts.rst index f7ceb950..315d1815 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -42,7 +42,7 @@ This means that cyclic creation dependencies are impossible. :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract OwnedToken { // TokenCreator is a contract type that is defined below. @@ -173,7 +173,7 @@ return parameter list for functions. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f(uint a) private pure returns (uint b) { return a + 1; } @@ -187,7 +187,7 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { uint private data; @@ -231,7 +231,7 @@ when they are declared. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { uint public data = 42; @@ -251,7 +251,7 @@ it evaluates to a state variable. If it is accessed externally :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { uint public data; @@ -270,7 +270,8 @@ to write a function, for example: :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; + contract arrayExample { // public state variable uint[] public myArray; @@ -295,7 +296,7 @@ The next example is more complex: :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Complex { struct Data { @@ -330,7 +331,7 @@ inheritable properties of contracts and may be overridden by derived contracts. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract owned { constructor() public { owner = msg.sender; } @@ -456,7 +457,7 @@ value types and strings. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { uint constant x = 32**22 + 8; @@ -499,7 +500,7 @@ The following statements are considered modifying the state: :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract C { function f(uint a, uint b) public view returns (uint) { @@ -544,7 +545,7 @@ In addition to the list of state modifying statements explained above, the follo :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract C { function f(uint a, uint b) public pure returns (uint) { @@ -632,7 +633,7 @@ Like any function, the fallback function can execute complex operations as long :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract Test { // This function is called for all messages sent to @@ -683,7 +684,7 @@ The following example shows overloading of the function :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract A { function f(uint _in) public pure returns (uint out) { @@ -701,7 +702,7 @@ externally visible functions differ by their Solidity types but not by their ext :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; // This will not compile contract A { @@ -734,7 +735,7 @@ candidate, resolution fails. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract A { function f(uint8 _in) public pure returns (uint8 out) { @@ -794,7 +795,7 @@ All non-indexed arguments will be :ref:`ABI-encoded <ABI>` into the data part of :: - pragma solidity ^0.4.21; + pragma solidity >=0.4.21 <0.6.0; contract ClientReceipt { event Deposit( @@ -851,7 +852,7 @@ as topics. The event call above can be performed in the same way as :: - pragma solidity ^0.4.10; + pragma solidity >=0.4.10 <0.6.0; contract C { function f() public payable { @@ -899,7 +900,7 @@ Details are given in the following example. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract owned { constructor() public { owner = msg.sender; } @@ -971,7 +972,7 @@ Note that above, we call ``mortal.kill()`` to "forward" the destruction request. The way this is done is problematic, as seen in the following example:: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract owned { constructor() public { owner = msg.sender; } @@ -1000,7 +1001,7 @@ derived override, but this function will bypass ``Base1.kill``, basically because it does not even know about ``Base1``. The way around this is to use ``super``:: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract owned { constructor() public { owner = msg.sender; } @@ -1059,7 +1060,7 @@ equivalent to ``constructor() public {}``. For example: :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract A { uint public a; @@ -1089,7 +1090,7 @@ The constructors of all the base contracts will be called following the linearization rules explained below. If the base constructors have arguments, derived contracts need to specify all of them. This can be done in two ways:: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract Base { uint x; @@ -1148,7 +1149,7 @@ error "Linearization of inheritance graph impossible". :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract X {} contract A is X {} @@ -1179,7 +1180,7 @@ Abstract Contracts Contracts are marked as abstract when at least one of their functions lacks an implementation as in the following example (note that the function declaration header is terminated by ``;``):: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Feline { function utterance() public returns (bytes32); @@ -1187,7 +1188,7 @@ Contracts are marked as abstract when at least one of their functions lacks an i 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; + pragma solidity >=0.4.0 <0.6.0; contract Feline { function utterance() public returns (bytes32); @@ -1238,7 +1239,7 @@ Interfaces are denoted by their own keyword: :: - pragma solidity ^0.4.11; + pragma solidity >=0.4.11 <0.6.0; interface Token { enum TokenType { Fungible, NonFungible } @@ -1300,7 +1301,7 @@ more advanced example to implement a set). :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; library Set { // We define a new struct datatype that will be used to @@ -1374,7 +1375,7 @@ custom types without the overhead of external function calls: :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; library BigInt { struct bigint { @@ -1515,7 +1516,7 @@ available without having to add further code. Let us rewrite the set example from the :ref:`libraries` in this way:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; // This is the same code as before, just without comments library Set { @@ -1565,7 +1566,7 @@ Let us rewrite the set example from the It is also possible to extend elementary types in that way:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; library Search { function indexOf(uint[] storage self, uint value) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ae0abc49..80311a63 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -20,7 +20,7 @@ For example, suppose we want our contract to accept one kind of external calls with two integers, we would write something like:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract Simple { uint sum; @@ -40,7 +40,7 @@ The output parameters can be declared with the same syntax after the the sum and the product of the two given integers, then we would write:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract Simple { function arithmetic(uint _a, uint _b) @@ -99,7 +99,7 @@ Internal Function Calls Functions of the current contract can be called directly ("internally"), also recursively, as seen in this nonsensical example:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function g(uint a) public pure returns (uint ret) { return a + f(); } @@ -129,7 +129,7 @@ all function arguments have to be copied to memory. When calling functions of other contracts, the amount of Wei sent with the call and the gas can be specified with special options ``.value()`` and ``.gas()``, respectively:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract InfoFeed { function info() public payable returns (uint ret) { return 42; } @@ -176,7 +176,7 @@ parameters from the function declaration, but can be in arbitrary order. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { mapping(uint => uint) data; @@ -199,7 +199,7 @@ Those parameters will still be present on the stack, but they are inaccessible. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { // omitted name for parameter @@ -222,7 +222,7 @@ is compiled so recursive creation-dependencies are not possible. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract D { uint public x; @@ -345,7 +345,7 @@ the two variables have the same name but disjoint scopes. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract C { function minimalScoping() pure public { { @@ -366,7 +366,7 @@ In any case, you will get a warning about the outer variable being shadowed. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; // This will report a warning contract C { function f() pure public returns (uint) { @@ -386,7 +386,7 @@ In any case, you will get a warning about the outer variable being shadowed. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; // This will not compile contract C { function f() pure public returns (uint) { @@ -433,7 +433,7 @@ a message string for ``require``, but not for ``assert``. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract Sharer { function sendHalf(address payable addr) public payable returns (uint balance) { @@ -479,7 +479,7 @@ The following example shows how an error string can be used together with revert :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract VendingMachine { function buy(uint amount) public payable { diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index d2b7de9c..7b7dd0b0 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -57,7 +57,7 @@ array in the return statement. Pretty cool, huh? Example:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f() public pure returns (uint8[5] memory) { @@ -87,7 +87,7 @@ should be noted that you must declare them as static memory arrays. Examples:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { struct S { @@ -127,7 +127,7 @@ which will be extended in the future. In addition, Arachnid has written `solidit For now, if you want to modify a string (even when you only want to know its length), you should always convert it to a ``bytes`` first:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { string s; @@ -282,7 +282,7 @@ In the case of a ``contract A`` calling a new instance of ``contract B``, parent You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor. In this example:: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract B { constructor() public payable {} @@ -330,7 +330,7 @@ Can a contract pass an array (static size) or string or ``bytes`` (dynamic size) Sure. Take care that if you cross the memory / storage boundary, independent copies will be created:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { uint[20] x; @@ -367,7 +367,7 @@ contract level) with ``arrayname.length = <some new length>;``. If you get the :: - pragma solidity ^0.4.18; + pragma solidity >=0.4.18 <0.6.0; // This will not compile contract C { diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 5ba7ed12..2d4777e8 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -16,7 +16,7 @@ Storage :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract SimpleStorage { uint storedData; @@ -80,7 +80,7 @@ registering with username and password — all you need is an Ethereum keypair. :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; contract Coin { // The keyword "public" makes those variables diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst index 11f85aac..d89ecded 100644 --- a/docs/layout-of-source-files.rst +++ b/docs/layout-of-source-files.rst @@ -13,6 +13,12 @@ and :ref:`pragma directives<pragma>`. Pragmas ======= +The ``pragma`` keyword can be used to enable certain compiler features +or checks. A pragma directive is always local to a source file, so +you have to add the pragma to all your files if you want enable it +in all of your project. If you :ref:`import<import>` another file, the pragma +from that file will not automatically apply to the importing file. + .. index:: ! pragma, version .. _version_pragma: @@ -43,6 +49,13 @@ the exact version of the compiler, so that bugfix releases are still possible. It is possible to specify much more complex rules for the compiler version, the expression follows those used by `npm <https://docs.npmjs.com/misc/semver>`_. +.. note:: + Using the version pragma will *not* change the version of the compiler. + It will also *not* enable or disable features of the compiler. It will just + instruct the compiler to check whether its version matches the one + required by the pragma. If it does not match, the compiler will issue + an error. + .. index:: ! pragma, experimental .. _experimental_pragma: @@ -261,7 +274,7 @@ for the two input parameters and two returned values. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; /** @title Shape calculator. */ contract ShapeCalculator { diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 5d2819df..12603f2e 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -48,7 +48,7 @@ non-elementary type, the positions are found by adding an offset of ``keccak256( So for the following contract snippet:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { struct s { uint a; uint b; } diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst index 8df12b7c..3305c1e1 100644 --- a/docs/security-considerations.rst +++ b/docs/security-considerations.rst @@ -55,7 +55,7 @@ complete contract): :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract Fund { @@ -78,7 +78,7 @@ as it uses ``call`` which forwards all remaining gas by default: :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract Fund { @@ -97,7 +97,7 @@ outlined further below: :: - pragma solidity ^0.4.11; + pragma solidity >=0.4.11 <0.6.0; contract Fund { /// Mapping of ether shares of the contract. @@ -182,7 +182,7 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract TxUserWallet { @@ -202,7 +202,7 @@ Now someone tricks you into sending ether to the address of this attack wallet: :: - pragma solidity >0.4.24; + pragma solidity >0.4.99 <0.6.0; interface TxUserWallet { function transferTo(address payable dest, uint amount) external; diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index d01886f8..0f9a71ab 100644 --- a/docs/solidity-by-example.rst +++ b/docs/solidity-by-example.rst @@ -36,7 +36,7 @@ of votes. :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; /// @title Voting with delegation. contract Ballot { @@ -225,7 +225,7 @@ activate themselves. :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract SimpleAuction { // Parameters of the auction. Times are either @@ -542,7 +542,7 @@ Safe Remote Purchase :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract Purchase { uint public value; @@ -793,7 +793,7 @@ The full contract :: - pragma solidity ^0.4.24; + pragma solidity >=0.4.24 <0.6.0; contract ReceiverPays { address owner = msg.sender; @@ -988,7 +988,7 @@ The full contract :: - pragma solidity ^0.4.24; + pragma solidity >=0.4.24 <0.6.0; contract SimplePaymentChannel { address payable public sender; // The account sending payments. diff --git a/docs/structure-of-a-contract.rst b/docs/structure-of-a-contract.rst index d8bc51b8..582e5338 100644 --- a/docs/structure-of-a-contract.rst +++ b/docs/structure-of-a-contract.rst @@ -26,7 +26,7 @@ storage. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract SimpleStorage { uint storedData; // State variable @@ -46,7 +46,7 @@ Functions are the executable units of code within a contract. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract SimpleAuction { function bid() public payable { // Function @@ -68,7 +68,7 @@ Function modifiers can be used to amend the semantics of functions in a declarat :: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract Purchase { address public seller; @@ -95,7 +95,7 @@ Events are convenience interfaces with the EVM logging facilities. :: - pragma solidity ^0.4.21; + pragma solidity >=0.4.21 <0.6.0; contract SimpleAuction { event HighestBidIncreased(address bidder, uint amount); // Event @@ -119,7 +119,7 @@ Structs are custom defined types that can group several variables (see :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Ballot { struct Voter { // Struct @@ -140,7 +140,7 @@ Enums can be used to create custom types with a finite set of 'constant values' :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Purchase { enum State { Created, Locked, Inactive } // Enum diff --git a/docs/style-guide.rst b/docs/style-guide.rst index b97beebd..7b48ccad 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -52,7 +52,7 @@ Surround top level declarations in solidity source with two blank lines. Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { // ... @@ -70,7 +70,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { // ... @@ -89,7 +89,7 @@ Blank lines may be omitted between groups of related one-liners (such as stub fu Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { function spam() public pure; @@ -109,7 +109,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { function spam() public pure { @@ -237,7 +237,7 @@ Import statements should always be placed at the top of the file. Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; import "./Owned.sol"; @@ -251,7 +251,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { // ... @@ -283,7 +283,7 @@ Within a grouping, place the ``view`` and ``pure`` functions last. Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { constructor() public { @@ -315,7 +315,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract A { @@ -411,7 +411,7 @@ should: Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Coin { struct Bank { @@ -422,7 +422,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract Coin { @@ -723,7 +723,7 @@ manner as modifiers if the function declaration is long or hard to read. Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // Base contracts just to make this compile contract B { @@ -755,7 +755,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // Base contracts just to make this compile contract B { @@ -955,7 +955,7 @@ As shown in the example below, if the contract name is `Congress` and the librar Yes:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // Owned.sol contract Owned { @@ -984,7 +984,7 @@ Yes:: No:: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // owned.sol contract owned { diff --git a/docs/types.rst b/docs/types.rst index ca1bd586..f9fc80ce 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -425,9 +425,37 @@ a non-rational number). String Literals --------------- -String literals are written with either double or single-quotes (``"foo"`` or ``'bar'``). They do not imply trailing zeroes as in C; ``"foo"`` represents three bytes not four. As with integer literals, their type can vary, but they are implicitly convertible to ``bytes1``, ..., ``bytes32``, if they fit, to ``bytes`` and to ``string``. +String literals are written with either double or single-quotes (``"foo"`` or ``'bar'``). They do not imply trailing zeroes as in C; ``"foo"`` represents three bytes, not four. As with integer literals, their type can vary, but they are implicitly convertible to ``bytes1``, ..., ``bytes32``, if they fit, to ``bytes`` and to ``string``. + +String literals support the following escape characters: + + - ``\<newline>`` (escapes an actual newline) + - ``\\`` (backslash) + - ``\'`` (single quote) + - ``\"`` (double quote) + - ``\b`` (backspace) + - ``\f`` (form feed) + - ``\n`` (newline) + - ``\r`` (carriage return) + - ``\t`` (tab) + - ``\v`` (vertical tab) + - ``\xNN`` (hex escape, see below) + - ``\uNNNN`` (unicode escape, see below) + +``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence. + +The string in the following example has a length of ten bytes. +It starts with a newline byte, followed by a double quote, a single +quote a backslash character and then (without separator) the +character sequence ``abcdef``. -String literals support escape characters, such as ``\n``, ``\xNN`` and ``\uNNNN``. ``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence. +:: + + "\n\"\'\\abc\ + def" + +Any unicode line terminator which is not a newline (i.e. LF, VF, FF, CR, NEL, LS, PS) is considered to +terminate the string literal. Newline only terminates the string literal if it is not preceded by a ``\``. .. index:: literal, bytes @@ -446,8 +474,9 @@ Enums ----- Enums are one way to create a user-defined type in Solidity. They are explicitly convertible -to and from all integer types but implicit conversion is not allowed. The explicit conversions -check the value ranges at runtime and a failure causes an exception. Enums needs at least one member. +to and from all integer types but implicit conversion is not allowed. The explicit conversion +from integer checks at runtime that the value lies inside the range of the enum and causes a failing assert otherwise. +Enums needs at least one member. The data representation is the same as for enums in C: The options are represented by subsequent unsigned integer values starting from ``0``. @@ -455,7 +484,7 @@ subsequent unsigned integer values starting from ``0``. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill } @@ -515,6 +544,11 @@ omitted. Note that this only applies to function types. Visibility has to be specified explicitly for functions defined in contracts, they do not have a default. +Conversions: + +A value of external function type can be explicitly converted to ``address`` +resulting in the address of the contract of the function. + A function type ``A`` is implicitly convertible to a function type ``B`` if and only if their parameter types are identical, their return types are identical, their internal/external property is identical and the state mutability of ``A`` @@ -524,7 +558,7 @@ is not more restrictive than the state mutability of ``B``. In particular: - ``view`` functions can be converted to ``non-payable`` functions - ``payable`` functions can be converted to ``non-payable`` functions -No other conversions are possible. +No other conversions between function types are possible. The rule about ``payable`` and ``non-payable`` might be a little confusing, but in essence, if a function is ``payable``, this means that it @@ -544,10 +578,12 @@ Note that public functions of the current contract can be used both as an internal and as an external function. To use ``f`` as an internal function, just use ``f``, if you want to use its external form, use ``this.f``. -Additionally, public (or external) functions also have a special member called ``selector``, +Members: + +Public (or external) functions also have a special member called ``selector``, which returns the :ref:`ABI function selector <abi_function_selector>`:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract Selector { function f() public pure returns (bytes4) { @@ -557,7 +593,7 @@ which returns the :ref:`ABI function selector <abi_function_selector>`:: Example that shows how to use internal function types:: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; library ArrayUtils { // internal functions can be used in internal library functions because @@ -608,7 +644,7 @@ Example that shows how to use internal function types:: Another example that uses external function types:: - pragma solidity ^0.4.22; + pragma solidity >=0.4.22 <0.6.0; contract Oracle { struct Request { @@ -691,7 +727,7 @@ memory-stored reference type do not create a copy. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract C { uint[] x; // the data location of x is storage @@ -773,7 +809,7 @@ or create a new memory array and copy every element. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f(uint len) public pure { @@ -795,7 +831,7 @@ assigned to a variable right away. :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract C { function f() public pure { @@ -816,7 +852,7 @@ possible: :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; // This will not compile. contract C { @@ -854,7 +890,7 @@ Members :: - pragma solidity ^0.4.16; + pragma solidity >=0.4.16 <0.6.0; contract ArrayContract { uint[2**20] m_aLotOfIntegers; @@ -934,7 +970,7 @@ shown in the following example: :: - pragma solidity ^0.4.11; + pragma solidity >=0.4.11 <0.6.0; contract CrowdFunding { // Defines a new type with two fields. @@ -1030,7 +1066,7 @@ each ``_KeyType``, recursively. For example with a mapping: :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract MappingExample { mapping(address => uint) public balances; @@ -1075,7 +1111,7 @@ value it referred to previously. :: - pragma solidity ^0.4.0; + pragma solidity >=0.4.0 <0.6.0; contract DeleteExample { uint data; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index c42a0068..3d119c82 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2039,7 +2039,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression) if (!contract) m_errorReporter.fatalTypeError(_newExpression.location(), "Identifier is not a contract."); if (contract->contractKind() == ContractDefinition::ContractKind::Interface) - m_errorReporter.fatalTypeError(_newExpression.location(), "Cannot instantiate an interface."); + m_errorReporter.fatalTypeError(_newExpression.location(), "Cannot instantiate an interface."); if (!contract->annotation().unimplementedFunctions.empty()) { SecondarySourceLocation ssl; diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index f7577cb3..78e45429 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -177,6 +177,8 @@ do then echo " - $dir" cd "$dir" + # Replace version pragmas + find . -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/' compileFull -w *.sol */*.sol cd .. fi diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 70503605..eb274c09 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -40,7 +40,7 @@ namespace { static char const* registrarCode = R"DELIMITER( -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract NameRegister { function addr(string memory _name) public view returns (address o_owner); diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index ae921a96..e82f389f 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -53,7 +53,7 @@ static char const* registrarCode = R"DELIMITER( // @authors: // Gav Wood <g@ethdev.com> -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract Registrar { event Changed(string indexed name); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index e0e3045c..9fe02e46 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -56,7 +56,7 @@ static char const* walletCode = R"DELIMITER( // some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the // interior is executed. -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract multiowned { diff --git a/test/externalTests.sh b/test/externalTests.sh index f2839083..0168fb03 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -56,10 +56,10 @@ function test_truffle echo "Current commit hash: `git rev-parse HEAD`" npm install find . -name soljson.js -exec cp "$SOLJSON" {} \; - if [ "$name" == "Gnosis" ]; then + if [ "$name" == "Zeppelin" -o "$name" == "Gnosis" ]; then echo "Replaced fixed-version pragmas..." # Replace fixed-version pragmas in Gnosis (part of Consensys best practice) - find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity 0/pragma solidity ^0/' + find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/' fi assertsol="node_modules/truffle/build/Assert.sol" if [ -f "$assertsol" ] |