trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

Strange compiler response for syntax error #415

Closed illuzen closed 7 years ago

illuzen commented 7 years ago

Just thought I'd pass this along. If you don't put parenthesis around your return type in the function signature, for example like this

  function casth(bytes32 n) public returns uint256 {

you get this:

5 5

/usr/local/lib/node_modules/truffle/node_modules/solc/wrapper.js:48 throw e; ^ abort(5) at Error at jsStackTrace (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:1:19718) at stackTrace (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:1:19901) at abort (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:19:15285) at Array.dXb (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:11:585101) at Array.tX (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:8:557453) at Array.eea (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:6:495332) at Object.wOb [as dynCall_ii] (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:11:540050) at invoke_ii (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:1:1275129) at Array.ixa (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:7:494308) at Object.bVb [as dynCall_viii] (/usr/local/lib/node_modules/truffle/node_modules/solc/soljson.js:11:577232) If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

This will probably confuse noobs, which might be a good thing. It will make them stronger. It's not like there's anywhere else for them to go.

Environment

pimotte commented 7 years ago

The same is displayed if you use "String" instead of "string" or use "type" as a variable name. I haven't actually seen a sane compiler error, so I don't even know if this functionality exists? (clearly, I'm one of the above-mentioned noobs).

illuzen commented 7 years ago

🤣 we should definitely strive for clear error messages. I've been meaning to dig into the compiler sauce, so maybe I'll make that my first project, make it spit out at least a line number or something. Whatever I have at /usr/local/bin/solc gives reasonable errors, so it's probably just a matter of passing them thru the javascript.

marcabbink commented 7 years ago

Yes I'm sure we're gonna save a lot of people a lot of time by checking for these things when compiling

I had another one. A variable with the name "contract"

paulhauner commented 7 years ago

This error is also generated if you happen to replace contracts/Migrations.sol with the code demonstrated here: http://truffle.readthedocs.io/en/beta/getting_started/migrations/

The actual Migrations.sol code generated by truffle init (on v3.2.5) is different to the code stated at the above link which does not build.

tinder-dyakobian commented 7 years ago

How the hell am I supposed to debug my code :(. I waited until writing 10 contracts to compile

beether commented 7 years ago

If it says: Compiling ./contracts/MyContract.sol... and then I see this 5 5 error, is it safe to assume the error is in MyContract.sol, or is it in the next (not printed) contract?

beether commented 7 years ago

Wow you cannot even see which file is getting the compilation error. Can this be high prio please?

GlenDC commented 7 years ago

Might try to make time for this to help with this issue if no one is pushing any PR for this yet.

illuzen commented 7 years ago

@GlenDC I spent a little time on it, didn't figure out which layer it's occurring at, so have at it. 👍

beether commented 7 years ago

@illuzen @GlenDC I'm interested at taking a crack at it, but I can't find the source code for truffle other than the giant bundle. Is there some other branch I can checkout?

jjc12 commented 7 years ago

I'm getting this error too, it's annoying

jjc12 commented 7 years ago

Honestly, I think it's because I'm trying to index a byte array, and then overwrite it. That is not allowed in Solidity; indexing is read-only.

mezzomix1810 commented 7 years ago

Had the same problem. Took me very long to debug. Using linter-solidity for Atom helped. (in case u use Atom) https://atom.io/packages/linter-solidity

illuzen commented 7 years ago

@beether from the giant bundle's README: https://github.com/trufflesuite/truffle-core

eugene-babichenko commented 7 years ago

The same problem too. Just because of a typo in a variable name in an expression like abc += 1.

tcoulter commented 7 years ago

This is an error in Solidity. It will be fixed when we upgrade to Solidity 0.4.13. Please see #484 to track our progress. Thanks!

dyba commented 7 years ago

None of the answers helped me but adding Solium to my tool chain and running the commands:

solium --init
solium --dir .

In the root of the project, helped pinpoint the errors in my .sol files. After I addressed the errors, running truffle compile and truffle migrate worked fine.

tcoulter commented 7 years ago

This issue has been fixed. Please upgrade to the latest version of Truffle. Thanks!