Clarify scope of 'using A for B' (#4252)

* Issue 1213: Clarify scope of 'using A for B'

* Typo fix.

* Further restructuring and clarification of contracts doc.

* Revert closer to original wording and formatting.
This commit is contained in:
Mike 2018-06-29 12:21:39 +02:00 committed by chriseth
parent c9cab80389
commit 2a9d54af58

View File

@ -1402,24 +1402,25 @@ Using For
********* *********
The directive ``using A for B;`` can be used to attach library The directive ``using A for B;`` can be used to attach library
functions (from the library ``A``) to any type (``B``). functions (from the library ``A``) to any type (``B``).
These functions will receive the object they are called on These functions will receive the object they are called on
as their first parameter (like the ``self`` variable in as their first parameter (like the ``self`` variable in Python).
Python).
The effect of ``using A for *;`` is that the functions from The effect of ``using A for *;`` is that the functions from
the library ``A`` are attached to any type. the library ``A`` are attached to *any* type.
In both situations, all functions, even those where the In both situations, *all* functions in the library are attached,
type of the first parameter does not match the type of even those where the type of the first parameter does not
the object, are attached. The type is checked at the match the type of the object. The type is checked at the
point the function is called and function overload point the function is called and function overload
resolution is performed. resolution is performed.
The ``using A for B;`` directive is active for the current The ``using A for B;`` directive is active only within the current
scope, which is limited to a contract for now but will contract, including within all of its functions, and has no effect
be lifted to the global scope later, so that by including outside of the contract in which it is used. The directive
a module, its data types including library functions are may only be used inside a contract, not inside any of its functions.
By including a library, its data types including library functions are
available without having to add further code. available without having to add further code.
Let us rewrite the set example from the Let us rewrite the set example from the