./node_modules/.bin/truffle works great (compile, migrate & test), but when I try ./node_modules/.bin/solidity-coverage I get the following error:
Compiling your contracts...
===========================
Error: CompileError: ParsedContract.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
ParserError: missing ';' at '(' (39:15)
I'm using solidity-coverage 0.6.2 and my solidity version is 0.5.10
This is almost certainly an issue with the preprocessor - are you able to share the contracts you're seeing this on? If not, any unusual syntax you're using is probably the cause - are you using anything that isn't tested for in the tests? Emoji or similar characters in your comments also causes this.
Also @amxx if you link to the project we can run it, find the problem and add a regression test for it here.
The compilation message is coming from Truffle and I think the absence of a filename there is a recently introduced bug (>= v.5.0.13). You might have luck downgrading Truffle temporarily to 5.0.12 to see if you get a more informative error.
@area The code is not public but I could send you an archive by email
I encountered the same error with [email protected] but after upgrading Truffle to ^5.0.27 the content of the error log changed as following:
Compiling your contracts...
===========================
- Fetching solc version list from solc-bin. Attempt #1
Error: Could not find ; from any sources; imported from path/to/my/project/coverageEnv/contracts/MyContract.sol
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/index.js:84:1
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/internal/onlyOnce.js:12:1
at next (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/whilst.js:68:1)
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/index.js:71:1
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/fs.js:85:1
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/internal/once.js:12:1
at replenish (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/internal/eachOfLimit.js:61:1)
at iterateeCallback (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/internal/eachOfLimit.js:50:1)
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/~/async/internal/onlyOnce.js:12:1
at ReadFileContext.callback (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-resolver/fs.js:81:1)
at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:242:13)
With [email protected], I got the following error:
Compiling your contracts...
===========================
- Fetching solc version list from solc-bin. Attempt #1
Error: CompileError: ParsedContract.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
ParserError: missing ';' at '(' (15:36)
^---------^
Compilation failed. See above.
at async.whilst.error (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:375:1)
at path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:969:1
at next (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:5222:1)
at Promise.all.then.results (path/to/my/project/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:357:1)
@seita-uc Could you paste MyContract.sol here? Or link to a public repo where it resides?
@cgewecke
The MyContract.sol was below:
pragma solidity >0.4.99 <0.6.0;
import "./Account.sol";
contract Factory {
bytes32 private contractCodeHash;
constructor() public {
contractCodeHash = keccak256(
type(Account).creationCode
);
}
}
and Account.sol is below:
pragma solidity >0.4.99 <0.6.0;
contract Account {
address public owner;
constructor(address payable _owner) public {
owner = _owner;
}
function setOwner(address _owner) public {
require(msg.sender == owner);
owner = _owner;
}
function destroy(address payable recipient) public {
require(msg.sender == owner);
selfdestruct(recipient);
}
function() payable external {}
}
Also, this is my .solcover.js
module.exports = {
compileCommand: '../node_modules/.bin/truffle compile',
skipFiles: ['MyContract.sol']
};
I was skipping MyContract.sol because instrumenting MyContract.sol caused following error:
There was a problem instrumenting ./coverageEnv/contracts/MyContract.sol: ParserError: missing ';' at '(' (10:36)
@seita-uc I think #350 will fix this - we needed to update our parser version for the type keyword syntax.
@amxx Can you confirm that your error is related to using type ?
Just like @seita-uc, the contracts in question are skipped because they caused an error
There was a problem instrumenting ./coverageEnv/contracts/registries/AppRegistry.sol: ParserError: missing ';' at '(' (39:15)
line 39 is:
App app = App(_create2(type(App).creationCode, salt));
So yes, the keyword type might be the issue here as well
@Amxx @seita-uc #350 is published in 0.6.3. Just lmk if that doesn't fix this....
@cgewecke it worked! Thank you!
Most helpful comment
@seita-uc I think #350 will fix this - we needed to update our parser version for the
typekeyword syntax.@amxx Can you confirm that your error is related to using
type?