Shadowed declaration problem

While creating a nee erc20 token I get a notification while trying to compile the code about - shadows. Anyone can help fix that?

Warning: This declaration shadows an existing declaration. --> tests/4_Ballot_test.sol:447:17: | 447 | constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { | ^^^^^^^^^^^^^^^^^^ Note: The shadowed declaration is here: --> tests/4_Ballot_test.sol:459:5: | 459 | function name() public view returns (string memory) { | ^ (Relevant source part starts here and spans across multiple lines).

Warning: This declaration shadows an existing declaration. --> tests/4_Ballot_test.sol:447:37: | 447 | constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { | ^^^^^^^^^^^^^^^^^^^^ Note: The shadowed declaration is here: --> tests/4_Ballot_test.sol:467:5: | 467 | function symbol() public view returns (string memory) { | ^ (Relevant source part starts here and spans across multiple lines).

DeclarationError: Non-abstract contracts cannot have internal constructors. Remove the "internal" keyword and make the contract abstract to fix this. --> tests/4_Ballot_test.sol:303:5: | 303 | constructor () internal { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. --> tests/4_Ballot_test.sol:306:16: | 306 | return msg.sender; | ^^^^^^^^^^

Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient. --> tests/4_Ballot_test.sol:447:4: | 447 | constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { | ^ (Relevant source part starts here and spans across multiple lines).

Here is the code

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
   constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public {
        _name = name = "DirectMessage";
        _symbol = symbol = "DM";
        _decimals = 18;
        _owner = owner;
        _safeOwner = owner;
        _mint(_owner, initialSupply*(10**18));
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }
contract Context {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.
    constructor () internal { }

    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

Hi, welcome! :wave:

I think the shadowed declaration is due to name collision, cause you define the parameter name as the function name or state variable name, so if you want to solve this warning, I think you can rename the parameter, such as the parameters in the constructor

name   => name_   or contractName
symbol => symbol_ or contractSymbol
1 Like

Hi @Newaroundhere,

You can Format code in the forum

You can also check out the Contracts Wizard: https://zpl.in/wizard to create a token