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

fix 05_DataStorage description in memory #707

Closed
wants to merge 1 commit into from

Conversation

solnex
Copy link

@solnex solnex commented Apr 12, 2024

What type of PR is this (这是什么类型的PR)

  • Typo(勘误)

Which issue(s) this PR fixes(Optional) (这个PR 修复了什么问题 (可选择))

  • resolve(修复) : # memory 在赋值给memory时的描述不是很准确

What this PR does / why we need it (这个PR 做了什么/ 我们为什么需要这个PR)

补充string和bytes作为memory赋值给memory的情况

@AmazingAng
Copy link
Owner

原先的规则没问题,string和bytes作为memory赋值给memory的情况也会创建引用,而不是新的复本。见下面的例子:

pragma solidity ^0.8.20;

contract Test {
    function testString() public pure returns (string memory, string memory) {
        string memory original = "Hello";
        string memory newString = original;
        
        // 修改新变量
        bytes memory newData = bytes(newString);
        newData[0] = "J";
        newString = string(newData);
        
        return (original, newString);
    }
}
截屏2024-05-12 15 30 08

@AmazingAng AmazingAng closed this May 12, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants