mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-21 08:31:33 +03:00
854 B
854 B
Unexpected statement: expected "x" -- got "y"
Example
This error occurs when a statement, which isn't if
, follows else
directly.
Erroneous code example:
function main () {
if true {
console.log("It was true.");
} else
console.log("It was false.");
}
The compiler will reject this code with:
Error [EPAR0370008]: unexpected statement: expected 'Block or Conditional', got 'console.log("It was false.", );'
--> test.leo:5:9
|
5 | console.log("It was false.");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Solutions
To fix the problem, wrap the statement in a block, so by turning the snippet above into...:
function main () {
if true {
console.log("It was true.");
} else {
console.log("It was false.");
}
}
...the error is fixed.