In the following code, I am returning a wrong value but there is no syntax error:

pragma solidity ^0.5.1;
contract C1 {
  function g(uint a) public returns (uint) {  f(a); }
  function f(uint) public returns(bool) { } 

function f(..) returns a boolean value but function g(..) requires uint.

Somebody please guide me why I am not getting any syntax error?

  • Elaborate more on why you think there should be a problem. The functions return different types. That's okay. – Rob Hitchens Jul 3 '19 at 2:38
  • Its violating the function g(...)' s return policy. function g(...) says that it would return uint but function g() is calling function f() whose return statement says that it would return bool which is against the return statement of g(). Is there any respect for 'returns (uint)' statement in function g()? – zak100 Jul 3 '19 at 3:55
  • It doesnt actually compile without ; after g. They are independent. – Rob Hitchens Jul 3 '19 at 4:10
  • Sorry I can't understand this term "; after g". – zak100 Jul 3 '19 at 4:18
  • 1
    'return' is necessary for returning values. It worked. – zak100 Jul 3 '19 at 4:30

For the benefit of others who come across this.

The statement


invokes the function f() and ignores the response. The expected syntax error is raised when the return value of f() (bool) is explicitly returned:

function g(uint a) public returns(uint) {  return f(a); }

f() cannot be returned from g() because function g() ... returns(uint) and function f() ... returns(bool). bool is not uint so the types are incompatible, as expected.

Hope it helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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