Skip to content

Commit

Permalink
Added documentation for the fact that dynamic state tests on unowned …
Browse files Browse the repository at this point in the history
…references do not give any static type information.
  • Loading branch information
mcoblenz committed Dec 4, 2019
1 parent a91e2c3 commit 29ef397
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions solidity_user_guide/source/tutorial/states3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ When there may be an owner of an object, other references should not be used to
s.turnOff(); // Shouldn't change state of s through an unowned reference
}

When unowned references are used in dynamic state tests, the body of the test does NOT have additional state information. For example:

::

transaction foo(LightSwitch@unowned s) {
if (s in On) {
s.turnOff(); // STILL can't change state of s through an unowned reference
}
}

If you need to call a transaction that needs the referenced object to be in a particular state, you need to start with at least a ``shared`` reference (if not an ``owned`` or state-specifying reference).

Shared references
------------------
If there is no owner of an object, then all references to the object are shared. These references can be used to change the state of the referenced object, but be careful to not call functions that require ownership. For example:
Expand Down
12 changes: 12 additions & 0 deletions user_guide/source/tutorial/states3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ When there may be an owner of an object, other references cannot be used to modi
s.turnOff(); // COMPILE ERROR: can't change state of s through an unowned reference
}

When Unowned references are used in dynamic state tests, the body of the test does NOT have additional state information. For example:

::

transaction foo(LightSwitch@Unowned s) {
if (s in On) {
s.turnOff(); // STILL GET A COMPILE ERROR: can't change state of s through an unowned reference
}
}

If you need to call a transaction that needs the referenced object to be in a particular state, you need to start with at least a ``Shared`` reference (if not an ``Owned`` or state-specifying reference).

Shared references
------------------
If there is no owner of an object, then all references to the object are annotated ``Shared``. These references can be used to change the state of the referenced object, but invoking transactions that can only be called in some states requires a runtime check. For example:
Expand Down

0 comments on commit 29ef397

Please sign in to comment.