Solidity Tips

How to fix "Overview: parser error expected primary expression" in solidity

3 minutes

How to fix "Overview: parser error expected primary expression" in solidity

Introduction

The error "parser error expected primary expression" is one that you might see when compiling Solidity code. It's caused by a missing semicolon, which is used to group elements so that they can be parsed as a single unit. This article will show you how to find and fix the problem if it occurs in your code.

The Reason

The reason for this error is a missing semicolon at the end of your function. A semicolon is used to mark the end of a statement, and it's easy to miss when you're just writing code.

The parser error will appear in the overview section of your editor (or in some cases, you may see an error message on your browser).

The Fix

  • Add a semicolon
  • Add a variable
  • Add a function call
  • Add a parenthesis
  • Add a comma (,) or semicolon (;) to move the code to the next line. If you see this error, then it's possible that there is an extra semicolon at the end of your code. Remove that and try again!

You forget to add a semicolon.

For example, if you want to assign a value to x and then use the same variable in another expression, you should add a semicolon after the assignment. For example:

```

solidity

contract MyContract {

uint6 x;

x = 1; // Semicolon here means that this is an expression that returns nothing

assert(1 == x); // Warning! Asserts cannot return values!

```

Conclusion

Solidity is a great language, but it's not perfect. When encountered with the “Overview: parser error expected primary expression” error message, make sure to check your code for semicolons and take action accordingly.

Featured Blogs