Skip to content

mutable variables (immutable as default) #715

Closed as not planned
Closed as not planned
@ethers

Description

@ethers

Function parameters can be marked immutable.

Such variables are called immutable. The immutable property extends to expressions in the following way:

  • members of immutable expressions are immutable
  • index access to immutable expressions yields immutable expressions
  • (perhaps some other cases we forgot about)

Immutable expressions cannot be assigned to (or be used in ++ or -- expressions) and they cannot be passed to internal functions as arguments that are not marked as immutable.

For value types, the "immutable" property can be removed if they are rvalues (need to specify this some more), and also the transition from storage to memory and memory to storage can lose the immutable property.

Todo:

  • similar to isPure, collect data in the TypeChecker about whether an expression is immutable
  • add the immutable keyword
  • check that assignments and ++ and -- do not have immutable left-hand-sides
  • check that there is no assignment from an immutable expression to a mutable expression
  • check that arguments to function calls do not violate these rules

"The constant keyword for functions is currently not enforced by the compiler."

It sounds like Solidity can enforce this and refuse to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed due inactivityThe issue/PR was automatically closed due to inactivity.high effortA lot to implement but still doable by a single person. The task is large or difficult.high impactChanges are very prominent and affect users or the project in a major way.language design :rage4:Any changes to the language, e.g. new featuresneeds designThe proposal is too vague to be implemented right awaystaleThe issue/PR was marked as stale because it has been open for too long.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions