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

Multiple different pragma versions are not considered and file is randomly taken (probably iterator.next()) #70

Open
rbrtjhs opened this issue Jul 8, 2021 · 0 comments

Comments

@rbrtjhs
Copy link

rbrtjhs commented Jul 8, 2021

I had a problem when I pulled a project which had different versions of solidity files.

Example:
File1.sol:
pragma solidity >0.5.0 <=0.6.0

File2.sol
pragma solidity >0.5.0 <=0.7.0

Sometimes it will take solidity version from File2.sol, sometimes it will take solidity version from File1.sol.
What is problem?
If it randomly takes files and it takes pragma of File2.sol it will take solc 0.6.12 which will not be able to compile File1.

Here is a test which proves this:
Solidity:
File1.sol:

pragma solidity >=0.5.0 <0.6.0;

contract File1 {

}

File2.sol:

pragma solidity >=0.5.0 <0.7.0;

contract File2 {

}

Java:

@Test
    public void differentPragmas() {
        //delete /home/$user/.web3j folder to download evrerytime (fresh install) new solc version
        String currentUsersHomeDir = System.getProperty("user.home");
        try {
            FileUtils.deleteDirectory(Paths.get(currentUsersHomeDir + "/.web3j").toFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        List<String> source = new LinkedList<>();
        //it will download 0.6.12 version
        source.add("File2.sol");
        source.add("File1.sol");
        CompilerResult result = solidityCompiler.compileSrc("src/test/resources/issue-70", source, new String[0], SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
        Assert.assertTrue(result.errors.isEmpty());
    }

First commit in the PR #71 has the test which does not work and commit after contains a simple approach to the solution.

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

1 participant