Closed duaraghav8 closed 8 years ago
Thanks @duaraghav8. I'm trying to add test code for the using
statement pulled from here. I've never used the using
statement before, so it appears I may not be using it correctly. Here's the code I'm adding to test/doc_examples.sol
:
library UsingExampleLibrary {
function sum(uint[] storage self) returns (uint s) {
for (uint i = 0; i < self.length; i++)
s += self[i];
}
}
contract UsingExampleContract {
using UsingExampleLibrary for uint[];
}
Unfortunately, I get these two errors (two different tests):
SyntaxError: Expected "[", "constant", "internal", "memory", "private", "public", comment, end of line, identifier or whitespace but ";" found. Line: 250, Column: 39
SyntaxError: Expected "contract", "import", "library", comment, end of input, end of line or whitespace but "u" found. Line: 8, Column: 1
I'm having trouble finding any other documentation for the using
statement. In fact, searching for using
on solidity.readthedocs.io returns zero results (I suspect it's a common word so filtered out). Can you help at all?
Thanks!
As an aside, test/doc_examples.sol
is a place where I throw new constructs for a quick pass/fail, solely to see if they'll parse. We'll likely want better tests in the future, especially as the AST solidifies, but feel free to add things to the file as you add new features. Thanks again for your work.
Wait - from the looks of it, the documentation I found shows the using statement as a block level construct meant to exist within a library or contract. However, according to the PR, it looks as though you've made it a top-level construct on par with contract
and library
. Do you know what it's supposed to be? Is there any supporting documentation just for my edification?
Alright, so it turns out I was wrong above - you in fact did put the UsingStatement in the right place. But my example exposed an issue with your PR, in that it didn't allow for array types in the using command. I've change the type of type
to Type
to reflect this. In order to do so, I had to create a new PR: https://github.com/ConsenSys/solidity-parser/pull/12
I'm going to close this one so we don't have two open. Let's continue discussion on #12. If you could give me your opinion about the changes, and everything looks good, I'll go ahead and merge.
Thanks again!
ObjectExpression
now containstype: "Property"
fieldusing
statements. examples: