Skip to content

Is Type::StorageRef the "right" way to indicate a value is in storage? #1814

@smoelius

Description

@smoelius

My question concerns this code:

solang/src/sema/ast.rs

Lines 48 to 49 in 53202f8

/// Reference to storage, first bool is true for immutables
StorageRef(bool, Box<Type>),

In Solidity, an array, mapping, or struct is entirely in memory or entirely in storage.

One cannot, for example, have an in-memory array of in-storage arrays.

However, the above Type::StorageRef allows for such combinations.

Were any alternatives considered, e.g., a flag or enum to indicate where a value is stored?


EDIT: This issue seems related: #933

EDIT 2: This program provides an example of the problem: https://github.com/ethereum/solidity/blob/7e67811a82d55bb280f5a21e9b623e4c3d99fbca/test/libsolidity/semanticTests/events/event_indexed_string.sol

The cast on this line 7 performs a storage load and a cast of the resulting, in-memory value:

return Expression::StorageLoad {
loc: *loc,
ty: *r,
expr: Box::new(self.clone()),
}
.cast(loc, to, implicit, ns, diagnostics);

Thus, the pushes are performed to the in-memory value only, and storage is not modified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions