question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax error when using the new constructor syntax

See original GitHub issue

From solidity v0.4.22 onwards, the new syntax for constructors is:

pragma solidity ^0.4.23;
contract MyContract {
    constructor() public {
        // initialize things
    }
}

The previous version using the contract’s name is now deprecated:

pragma solidity ^0.4.23;
contract MyContract {
    function MyContract() public {
        // initialize things
    }
}

On VSCode using this extension, I get the following error when using the new syntax: ParserError: Expected identifier, got 'LParen' constructor() public { ^.

When compiling my contracts with solc directly or with truffle I get deprecation warnings when using the old syntax, and the new one works well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
juanfranblancocommented, Apr 30, 2018

It has been upgraded and released now. Please reopen if you see any issues. Thanks again @duaraghav8 !!

2reactions
juanfranblancocommented, Apr 21, 2018

@tsauvajon that is an issue with the linter https://github.com/duaraghav8/Solium/issues/198. I’ll keep this open to update it ASAP as it gets added to solium.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError() constructor - JavaScript - MDN Web Docs
SyntaxError() constructor. The SyntaxError constructor creates a new error object that represents an error when trying to interpret syntactically invalid code.
Read more >
Syntax Error when call Error.constructor with a string including ...
First off, Error.constructor is actually Object.constructor : > Error.constructor === Object.constructor true. Second, Object.constructor ...
Read more >
SyntaxError - JavaScript: The Definitive Guide, 6th Edition [Book]
When the SyntaxError() constructor is called as a function, without the new operator, it behaves just as it does when called with the...
Read more >
SML/NJ Error Messages
This error occurs when type constructors with incompatible equality properties are equated by sharing constraints. When this happens, the signature is not ...
Read more >
Syntax Error in CONSTRUCTOR method - but Why?
In the book "Next Generation ABAP Development" (by Rich Heilman and Thomas Jung) there are examples that do use Private constructors just like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found