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

Introduce immutable modifier #1125

Closed
biqas opened this issue Mar 8, 2015 · 1 comment
Closed

Introduce immutable modifier #1125

biqas opened this issue Mar 8, 2015 · 1 comment
Labels
Area-Language Design Feature Request Resolution-Duplicate The described behavior is tracked in another issue Verified

Comments

@biqas
Copy link

biqas commented Mar 8, 2015

Introducing immutable modifier on class, field, property, event, indexer and method level.

Benefits could be:

  • could help express the intention to better understand the class design and behavior
  • could make some assumption/prediction/facts for garbage collection.
  • could have some inference chain for not mixing immutable with mutable things.
  • could have positive effects for lock's
public immutable class A
{
    // so everything is immutable in the class
    public A Foo()
    {
        // not allowed.
        // return this;

        return new A();
    }
}
public class A
{
    private immutable int fieldA = 3;

    public A()
    {
        // allowed
        this.fieldA = 0;
    }

    public immutable A Foo()
    {
        // not allowed !!!
        this.fieldA = 42;

        return new A();
    }
}

So chain of immutable must be inspected to guarantee immutable remains immutable.

@pharring
Copy link
Contributor

pharring commented Mar 9, 2015

@biqas Thanks for the proposal. Immutability and immutable types are discussed in #159. Please review it and see if it covers all the scenarios you were thinking of. If there's something else, it's best to discuss it there.

Note that readonly on fields already takes care of your second example.

@pharring pharring closed this as completed Mar 9, 2015
@pharring pharring added the Resolution-Duplicate The described behavior is tracked in another issue label Mar 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Feature Request Resolution-Duplicate The described behavior is tracked in another issue Verified
Projects
None yet
Development

No branches or pull requests

4 participants