aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/contracts.rst23
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
-rw-r--r--test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol11
-rw-r--r--test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol11
4 files changed, 35 insertions, 12 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 5cfa7805..845fd973 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -1402,24 +1402,25 @@ Using For
*********
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
-as their first parameter (like the ``self`` variable in
-Python).
+as their first parameter (like the ``self`` variable in Python).
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
-type of the first parameter does not match the type of
-the object, are attached. The type is checked at the
+In both situations, *all* functions in the library are attached,
+even those where the type of the first parameter does not
+match the type of the object. The type is checked at the
point the function is called and function overload
resolution is performed.
-The ``using A for B;`` directive is active for the current
-scope, which is limited to a contract for now but will
-be lifted to the global scope later, so that by including
-a module, its data types including library functions are
+The ``using A for B;`` directive is active only within the current
+contract, including within all of its functions, and has no effect
+outside of the contract in which it is used. The directive
+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.
Let us rewrite the set example from the
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 77e7cf67..b9e3f8d0 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -929,7 +929,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
}
else if (var->type()->dataStoredIn(DataLocation::Storage))
{
- m_errorReporter.typeError(_identifier.location, "You have to use the _slot or _offset prefix to access storage reference variables.");
+ m_errorReporter.typeError(_identifier.location, "You have to use the _slot or _offset suffix to access storage reference variables.");
return size_t(-1);
}
else if (var->type()->sizeOnStack() != 1)
diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol
new file mode 100644
index 00000000..55c83674
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference.sol
@@ -0,0 +1,11 @@
+contract C {
+ uint[] x;
+ function() public {
+ uint[] storage y = x;
+ assembly {
+ pop(y)
+ }
+ }
+}
+// ----
+// TypeError: (117-118): You have to use the _slot or _offset suffix to access storage reference variables.
diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol
new file mode 100644
index 00000000..3ae24b34
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_fine.sol
@@ -0,0 +1,11 @@
+contract C {
+ uint[] x;
+ function() public {
+ uint[] storage y = x;
+ assembly {
+ pop(y_slot)
+ pop(y_offset)
+ }
+ }
+}
+// ----