Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bortzmeyer opened this issue May 23, 2016 · 17 comments

Comments

@bortzmeyer
Copy link

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
@Arachnid
Copy link
Owner

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

@bortzmeyer
Copy link
Author

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();
              ^---------------------------^

@Arachnid
Copy link
Owner

Arachnid commented May 23, 2016

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?

@bortzmeyer
Copy link
Author

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();
              ^-------------^

@Arachnid
Copy link
Owner

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?

@bortzmeyer
Copy link
Author

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
Copy link
Author

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) <caktux@gmail.com>
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

@Arachnid
Copy link
Owner

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.

@chriseth
Copy link
Contributor

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

@ghost
Copy link

ghost commented Aug 13, 2016

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

@Arachnid
Copy link
Owner

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

@ghost
Copy link

ghost commented Aug 20, 2016

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

@ghost
Copy link

ghost commented Aug 20, 2016

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
Copy link

ghost commented Aug 20, 2016

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

@Arachnid
Copy link
Owner

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.

@ghost
Copy link

ghost commented Aug 20, 2016

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

@nrchandan
Copy link

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

Arachnid pushed a commit that referenced this issue Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants