Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property overwriting not working? #3336

Closed
danutavadanei opened this issue Dec 15, 2017 · 3 comments
Closed

Property overwriting not working? #3336

danutavadanei opened this issue Dec 15, 2017 · 3 comments

Comments

@danutavadanei
Copy link

danutavadanei commented Dec 15, 2017

Description

The solidity compiler accepts inheritance overloading of both modifiers and functions. But what about properties?

Check this example:

pragma solidity ^0.4.18;

contract Animal {
    uint256 public age;
    
    function getAnimalAge() public constant returns (uint256) {
        return age;
    }
}


contract Dog is Animal {
    uint256 public age;
    
    function Dog(uint256 _age) public {
        age = _age;
    }
    
    function getDogAge() public constant returns (uint256) {
        return age;
    }
}

In this case, by initializing Dog contract with age 20 one would expect that Animal age property to be 20, right? No, this doesn't happen. Calling getDogAge function will return 20 and calling getAnimalAge will return 0.

I know solidity inheritance doesn't work as in other standard programming languages but shouldn't the inherit from properties that are overloaded to have the value assigned in the child?

You can test that out here.

@chriseth
Copy link
Contributor

Might be the same as #2563

@chriseth chriseth changed the title Property overloading not working? Property overwriting not working? Feb 13, 2018
@wbt
Copy link
Contributor

wbt commented Mar 7, 2018

See also #3675.

@Marenz
Copy link
Contributor

Marenz commented Jan 30, 2020

This example now gives an error when you try to override the property. I assume that finishes this ticket, if you feel different please re-open and discuss with us :)

@Marenz Marenz closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants