pragmas.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Pragmas
  2. =======
  3. A pragma value is a special directive to the compiler. It has a name, and a value. The name
  4. is an identifier and the value is any text terminated by a semicolon `;`. Solang parses
  5. pragmas but does not recognise any.
  6. Often, Solidity source files start with a ``pragma solidity`` which specifies the Ethereum
  7. Foundation Solidity compiler version which is permitted to compile this code. Solang does
  8. not follow the Ethereum Foundation Solidity compiler version numbering scheme, so these
  9. pragma statements are silently ignored. There is no need for a ``pragma solidity`` statement
  10. when using Solang.
  11. .. code-block:: solidity
  12. pragma solidity >=0.4.0 <0.4.8;
  13. pragma experimental ABIEncoderV2;
  14. The `ABIEncoderV2` pragma is not needed with Solang; structures can always be ABI encoded or
  15. decoded. All other pragma statements are ignored, but generate warnings.
  16. About pragma solidity versions
  17. ------------------------------
  18. Ethereum Solidity checks the value of ``pragma version`` against the compiler version, and
  19. gives an error if they do not match. Ethereum Solidity is often revising the language
  20. in various small ways which make versions incompatible which other. So, the
  21. version pragma ensures that the compiler version matches what the author of the
  22. contract was using, and ensures the compiler will give no unexpected errors.
  23. Solang takes a different view:
  24. #. Solang tries to remain compatible with different versions of ethereum solidity;
  25. we cannot publish a version of solang for every version of the ethereum solidity
  26. compiler.
  27. #. We also have compatibility issues because we target multiple blockchains, so
  28. the version would not be sufficient.
  29. #. We think that the compiler version should not be a property of the source,
  30. but of the build environment. No other language set the compiler version in
  31. the source code.
  32. If anything, some languages allow conditional compilation based on the compiler
  33. version, which is much more useful.