I wrote a sample Solidity code below: in function call() of contract sample_call, I make a call to function add_car() function of another contract sample, but this is a bug, since variable v is never initialized.

I assumed that solc should detect this issue, and complain, but in contrast it happily compiled the code.

Do you think that this is where solc should be improved?

pragma solidity ^0.4.1;

contract sample_call {
    function call() public pure {
        uint a;
        sample v;   // v is never initialized

        a = v.add_var(0x22); // BUG HERE, because v is uninitialized

contract sample {
    function add_var(uint a) public pure returns(uint) {
    return a + 0x55;


  • Please report such issues to their github.
    – Ismael
    Aug 23, 2018 at 18:37

1 Answer 1


There will be a runtime error but no compiler.

v is cast as a type Sample. So, it has Sample's methods, and you can do things like:

v = new Sample();


v = Sample(_sampleAddress);

Your contract does neither so function call() fails at runtime.

I don't think the solc team would consider that a bug. The static analysis group on the Remix team might consider it a useful suggestion if it's not already there. They raise all sorts of potential concerns about contracts that compile but possibly may not do what the author expects at runtime.

Hope it helps.

  • 1
    Access to uninitialized variables can be determined at compile time. And it is a nice feature to have.
    – Ismael
    Aug 23, 2018 at 19:47
  • It would be great if the compiler would suggest that there seems to be a contract in play it isn't instantiated by anything anywhere. It is "as designed", for now at least, so maybe it's more a feature request or gripe than "bug". Aug 23, 2018 at 20:24
  • It is only an opinion but v is never assigned a value, using it in languages like C, Java, etc. is a warning. I know that solidity initializes variables to zero, but using variables without an explicit initialization is not a great idea: Explicit is better than implicit.
    – Ismael
    Aug 23, 2018 at 20:36
  • 1
    I agree It is what it is, but maybe it should not be exactly like that. So, yeah, I think the solc would reject it as a bug report but the idea has merit, so this could be part of a crusade to overturn the status quo and anyone wants to carry the torch. Aug 23, 2018 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.