You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's more of a design choice than a bug, though whether it's a good one is up for discussion.
It works this way because both string storage store and string memory value are references and the assignment copies the reference, not the content. If we changed it, then it would be inconsistent with what happens when you assign between two string storage variables (it does not copy the content either, though in this case there is no error). The only case where an actual copy happens is when the target of the assignment is not a reference.
This is to some extent documented in Data location and assignment behaviour but it does not actually mention this case specifically. I also think the docs would be clearer if they properly distinguished between storage variables and references/pointers to them. The fact that they avoid making that distinction muddles the matter.
In any case, I don't think simply changing this behavior to make it copy is the solution here. We do have a solution to the general problem in mind, but that will require changes in the current copy/reference semantics. That's tracked in #2435 so I'm closing this issue. We'll likely end up introducing something like a copyof operator to make copies explicit.
cameel
changed the title
Bug: type string memory is not implicitelly convertible to type string storage pointer
Bug: type string memory is not implicitly convertible to type string storage pointer
Jan 27, 2023
Description
Consider the following code
store = value;
refused to compile with errorI would expect that to be valid, and to write the string in
value
to the storage slot corresponding tostore
Environment
Steps to Reproduce
Try to compile
The text was updated successfully, but these errors were encountered: