solidity-stringutils icon indicating copy to clipboard operation
solidity-stringutils copied to clipboard

Member "toSlice" not found or not visible after argument-dependent lookup

Open bortzmeyer opened this issue 8 years ago • 17 comments

I cannot use the library. Even with your own example:

    var len = "Unicode snowman ☃".toSlice().len();                                                                         

The compiler complains:

 % solc --abi registry.sol
registry.sol:26:15: Error: Member "toSlice" not found or not visible after argument-dependent lookup in literal_string "Unicode snowman ☃"
   uint len = "Unicode snowman ☃".toSlice().len(); 
              ^---------------------------^
% solc --v
solc, the solidity compiler commandline interface
Version: 0.3.2-0/Release-Linux/g++/Interpreter

bortzmeyer avatar May 23 '16 11:05 bortzmeyer

Have you imported it and done using strings for * as in the first example? Can you include a complete failing example, please?

Arachnid avatar May 23 '16 12:05 Arachnid

Yes, I believe I did everything. Here is a complete contract which is failing:

% cat test-strings.sol
// github.com/Arachnid/solidity-stringutils/strings.sol 
import "strings.sol";

contract MyStrings {

  using strings for *; 

  function MyStrings() {
    var len = "Unicode snowman ☃".toSlice().len();
  }

}

% solc test-strings.sol 
test-strings.sol:9:15: Error: Member "toSlice" not found or not visible after argument-dependent lookup in literal_string "Unicode snowman ☃"
    var len = "Unicode snowman ☃".toSlice().len();
              ^---------------------------^

bortzmeyer avatar May 23 '16 13:05 bortzmeyer

That should work fine - and it works fine in Browser Solidity. If it's not working in your local solc, and it's up to date, I don't know what else could be wrong.

Support for calling functions on string literals was added very recently - does strings.toSlice("Unicode snowman ☃").len() work?

Arachnid avatar May 23 '16 14:05 Arachnid

Same thing

% cat test-strings.sol
// github.com/Arachnid/solidity-stringutils/strings.sol 
import "strings.sol";

contract MyStrings {

  using strings for *; 

  function MyStrings() {
    // var len = "Unicode snowman ☃".toSlice().len();
    var len = strings.toSlice("Unicode snowman ☃").len();
  }

}

% solc test-strings.sol
test-strings.sol:10:15: Error: Member "toSlice" not found or not visible after argument-dependent lookup in type(library strings)
    var len = strings.toSlice("Unicode snowman ☃").len();
              ^-------------^

bortzmeyer avatar May 25 '16 16:05 bortzmeyer

Again, there's nothing more I can do: This exact code works for me in Browser Solidity, and on the command line (in the unittests) with the latest version of solc. There must be something wrong with your solc installation, or it's not actually the version it claims to be; it's definitely not a problem with the library.

Maybe ask in the solidity gitter channel?

Arachnid avatar May 25 '16 16:05 Arachnid

Actually, I don't even see how the functions could be visible outside of the library since they are marked as "internal" and the Solidity doc says "Those functions and state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using this."

bortzmeyer avatar May 26 '16 07:05 bortzmeyer

Regarding the risk that "my" solc is not the right one: I used the repository "http://ppa.launchpad.net/ethereum/ethereum/ubuntu xenial main":

%  solc --version
solc, the solidity compiler commandline interface
Version: 0.3.2-0/Release-Linux/g++/Interpreter

% dpkg -S $(which solc)
solc:amd64: /usr/bin/solc

% apt-cache show solc:amd64
Package: solc
Source: cpp-ethereum
Priority: extra
Section: science
Installed-Size: 363
Maintainer: caktux (Buildserver key) <[email protected]>
Architecture: amd64
Version: 1.2.4~xenial-0ubuntu1
Depends: libboost-filesystem1.58.0, libboost-program-options1.58.0, libboost-system1.58.0, libc6 (>= 2.14), libgcc1 (>= 1:3.0), libjsoncpp1, libstdc++6 (>= 5.2), libethereum (= 1.2.4~xenial-0ubuntu1)
Filename: pool/main/c/cpp-ethereum/solc_1.2.4~xenial-0ubuntu1_amd64.deb
Size: 106842
MD5sum: e3ef02748c94aa1d5755cbf11b599cd8
SHA1: 72f4a73919e0b7b08475c909987cd6c6730e71b8
SHA256: ebea03623c83eebf39b4dc0ce1256f3455e162f1d4afe6d503caecd8829b1919
Description-en: Solidity compiler (solc).
 Solidity compiler (solc).
Description-md5: 20debf85e6fc91af7ee1afca5fcc124c
Multi-Arch: same

bortzmeyer avatar May 26 '16 07:05 bortzmeyer

Actually, I don't even see how the functions could be visible outside of the library since they are marked as "internal" and the Solidity doc says "Those functions and state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using this."

Solidity recently added support for 'internal' functions in libraries; they're automatically linked into the calling code. This whole library is predicated around that feature.

Have you tried reproducing this in browser-solidity? The fact that it works there indicates it's not an issue with the library.

Arachnid avatar May 26 '16 09:05 Arachnid

You currently need the nightly version of solidity. We will release a new version 0.3.3 which will included that feature shortly.

chriseth avatar May 26 '16 09:05 chriseth

This is still failing in Browser Solidity (using 0.3.6), including pasting in some of the literal examples along with using strings for *.

ghost avatar Aug 13 '16 02:08 ghost

Can you give a complete example that fails in browser solidity, along with the error message you get?

Arachnid avatar Aug 15 '16 08:08 Arachnid

The error I got was exactly the same error that is in the title.

ghost avatar Aug 20 '16 17:08 ghost

Okay, here's an example: splitting a string into an array.

import "Strings.sol";

contract stringer {

using strings for *;

function toArray(string _string) {
var s = _string.toSlice();
var delim = ".".toSlice();
var parts = new strings.slice[](s.count(delim));
for(uint i = 0; i < parts.length; i++) {
    parts[i] = s.split(delim).toString();
    }
}

}

On the line containing parts[i] = s.split(delim).toString(); there is an error in browser solidity which says Type string memory not implicitly convertible to expected type struct slice memory.

ghost avatar Aug 20 '16 17:08 ghost

And I'm using solidity version: 0.3.6-0d736fde/Release-Emscripten/clang

ghost avatar Aug 20 '16 17:08 ghost

On the line containing parts[i] = s.split(delim).toString(); there is an error in browser solidity which says Type string memory not implicitly convertible to expected type struct slice memory.

That's a different issue; there was a bug in the example code (parts should be an array of strings, not an array of slices). I've updated the example with the correct code.

Arachnid avatar Aug 20 '16 17:08 Arachnid

That worked. Not sure exactly where the previous error appeared since it was a few days ago.

ghost avatar Aug 20 '16 18:08 ghost

Is there a way to specify the "using" statement without "*"? I tried "using strings for string;" but then it doesn't match literal_strings.

nrchandan avatar Jun 20 '17 05:06 nrchandan