mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6130 from ethereum/docs-pragma
[DOCS] Updates to Pragma docs
This commit is contained in:
commit
9193fcb99f
@ -35,7 +35,7 @@ The first line simply tells that the source code is written for
|
|||||||
Solidity version 0.4.0 or anything newer that does not break functionality
|
Solidity version 0.4.0 or anything newer that does not break functionality
|
||||||
(up to, but not including, version 0.6.0). This is to ensure that the
|
(up to, but not including, version 0.6.0). This is to ensure that the
|
||||||
contract is not compilable with a new (breaking) compiler version, where it could behave differently.
|
contract is not compilable with a new (breaking) compiler version, where it could behave differently.
|
||||||
So-called pragmas are common instructions for compilers about how to treat the
|
:ref:`Pragmas<pragma>` are common instructions for compilers about how to treat the
|
||||||
source code (e.g. `pragma once <https://en.wikipedia.org/wiki/Pragma_once>`_).
|
source code (e.g. `pragma once <https://en.wikipedia.org/wiki/Pragma_once>`_).
|
||||||
|
|
||||||
A contract in the sense of Solidity is a collection of code (its *functions*) and
|
A contract in the sense of Solidity is a collection of code (its *functions*) and
|
||||||
|
@ -13,11 +13,11 @@ and :ref:`pragma directives<pragma>`.
|
|||||||
Pragmas
|
Pragmas
|
||||||
=======
|
=======
|
||||||
|
|
||||||
The ``pragma`` keyword can be used to enable certain compiler features
|
The ``pragma`` keyword is used to enable certain compiler features
|
||||||
or checks. A pragma directive is always local to a source file, so
|
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
|
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
|
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.
|
from that file does not automatically apply to the importing file.
|
||||||
|
|
||||||
.. index:: ! pragma, version
|
.. index:: ! pragma, version
|
||||||
|
|
||||||
@ -26,34 +26,34 @@ from that file will not automatically apply to the importing file.
|
|||||||
Version Pragma
|
Version Pragma
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Source files can (and should) be annotated with a so-called version pragma to reject
|
Source files can (and should) be annotated with a version pragma to reject
|
||||||
being compiled with future compiler versions that might introduce incompatible
|
compilation with future compiler versions that might introduce incompatible
|
||||||
changes. We try to keep such changes to an absolute minimum and especially
|
changes. We try to keep these to an absolute minimum and
|
||||||
introduce changes in a way that changes in semantics will also require changes
|
introduce them in a way that changes in semantics also require changes
|
||||||
in the syntax, but this is of course not always possible. Because of that, it is always
|
in the syntax, but this is not always possible. Because of this, it is always
|
||||||
a good idea to read through the changelog at least for releases that contain
|
a good idea to read through the changelog at least for releases that contain
|
||||||
breaking changes, those releases will always have versions of the form
|
breaking changes. These releases always have versions of the form
|
||||||
``0.x.0`` or ``x.0.0``.
|
``0.x.0`` or ``x.0.0``.
|
||||||
|
|
||||||
The version pragma is used as follows::
|
The version pragma is used as follows::
|
||||||
|
|
||||||
pragma solidity ^0.5.2;
|
pragma solidity ^0.5.2;
|
||||||
|
|
||||||
Such a source file will not compile with a compiler earlier than version 0.5.2
|
A source file with the line above does not compile with a compiler earlier than version 0.5.2,
|
||||||
and it will also not work on a compiler starting from version 0.6.0 (this
|
and it also does not work on a compiler starting from version 0.6.0 (this
|
||||||
second condition is added by using ``^``). The idea behind this is that
|
second condition is added by using ``^``). This is because
|
||||||
there will be no breaking changes until version ``0.6.0``, so we can always
|
there will be no breaking changes until version ``0.6.0``, so you can always
|
||||||
be sure that our code will compile the way we intended it to. We do not fix
|
be sure that your code compiles the way you intended. The exact version of the
|
||||||
the exact version of the compiler, so that bugfix releases are still possible.
|
compiler is not fixed, so that bugfix releases are still possible.
|
||||||
|
|
||||||
It is possible to specify much more complex rules for the compiler version,
|
It is possible to specify more complex rules for the compiler version,
|
||||||
the expression follows those used by `npm <https://docs.npmjs.com/misc/semver>`_.
|
these follow the same syntax used by `npm <https://docs.npmjs.com/misc/semver>`_.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Using the version pragma will *not* change the version of the compiler.
|
Using the version pragma *does not* change the version of the compiler.
|
||||||
It will also *not* enable or disable features of the compiler. It will just
|
It also *does not* enable or disable features of the compiler. It just
|
||||||
instruct the compiler to check whether its version matches the one
|
instructs the compiler to check whether its version matches the one
|
||||||
required by the pragma. If it does not match, the compiler will issue
|
required by the pragma. If it does not match, the compiler issues
|
||||||
an error.
|
an error.
|
||||||
|
|
||||||
.. index:: ! pragma, experimental
|
.. index:: ! pragma, experimental
|
||||||
|
Loading…
Reference in New Issue
Block a user