1

Suddenly getting an error when doing a truffle compile --reset - even though I didn't make any code changes on my Migrations.sol file.

TypeError: Name has to refer to a struct, enum or contract.
    Migrations upgraded = Migrations(new_address);

I mean I get that the contract's name is Migrations, but this was always the case. Why is this suddenly happening now is what I'd like to know. And how do you fix it?

Its especially weird given that this Migrations.sol file wasn't even written by me, as its automatically provided when you create a new project.

(Would this have anything to do with the new version of Truffle - meaning 5.0.2?)

  • You're not telling us everything. By moving from Truffle 4.x to Truffle 5.x, you have essentially updated the compiler version from 0.4.x to 0.5.x. This by itself should have given you a single error for each one of your sol files: SyntaxError: Source file requires different compiler version. So you have by the least changed the pragma statement in your Migrations.sol file. – goodvibration Jan 20 at 14:15
1

I can reproduce this error only with solidity 0.5.x, so I am guessing that you're using truffle 5.x. You can check the version by calling truffle version

Actually you should see three errors

  • SyntaxError: Source file requires different compiler version
  • SyntaxError: Functions are not allowed to have the same name as the contract.
  • TypeError: Name has to refer to a struct, enum or contract.

The last one is a consequential error due to the first two. So if you fix the pragma and constructor it should disappear.

pragma solidity ^0.5.0;

contract ... {
    ...
    constructor() public {
       ...
    }
    ...
}

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.