0

If I do

msg.sender.call.value(1 ether);

It looks like I will send msg.sender 1 ether where I want to execute the fallback function.

However, it does NOT call it because I did not provide the brackets () for the arguments.

Why is this valid syntax?

| improve this question | | | | |
0

I'm not sure you'll get a good answer to this "why" question, unless someone who worked on the early design of Solidity can chime in with their rationale.

Note that the following code also compiles:

function test() pure internal { }
function test2() pure internal {
    test;
    5;
}

Just like in your example, test; is valid syntactically but has no effect. No compiler warning is emitted.

Interestingly, the line 5; does emit a warning: "Statement has no effect." This means the compiler does have some ability to recognize this sort of situation. I think that leaves the door open to a future version of the compiler emitting a warning for test; or your original example (which I believe is equivalent). I'm not convinced it should be a syntax error, but a warning seems quite reasonable.

If you'd like to see this changed, I would encourage you to open an issue on GitHub.

| improve this answer | | | | |
0

smarx is right: your syntax is perfectly valid just because it does not translate into nothing in the bytecode side, so there's no real error in there.

Try to remove that line and the compiled byte code will result exactly the same.

You can see it as a syntax that produce an unintended comment. Why? Essentially because, even if it is improving fast, Solidity is still a language in its very early stage (currently latest release is the 0.4.24).

| 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.