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

Banning the use of non-static fields, properties, and methods. #1239

Open
Jim8y opened this issue Nov 10, 2024 · 4 comments
Open

Banning the use of non-static fields, properties, and methods. #1239

Jim8y opened this issue Nov 10, 2024 · 4 comments
Assignees

Comments

@Jim8y
Copy link
Contributor

Jim8y commented Nov 10, 2024

The use of non-static fields and properties are wrong, and can not be fixed in an easy way, the reason of the problem is that static field/property can be initialized in a static constructor, while non-static have to be initialized when an object is created, yet no instance will be created for smartcontract. Thus all non-static field/properties can not be initizalied properly. A solution of this would be inserting opcode to initialize those fields when loading the conrtact, but that will just be the same as banning the use of non-static fields/property, and it makes more sense for me since contract will not have any instance anyway (interoperation and reentry will be consisdered totally different environment, static field/property will not be shared.).

And to align with the banning of using non-static field/property, we can also ban the use of non-static methods, to make the experience unified.

@Jim8y
Copy link
Contributor Author

Jim8y commented Nov 10, 2024

        private readonly static UInt160 uInt160 = "NXV7ZhHiyM1aHXwpVsRZC6BwNFP2jghXAq";

        private BigInteger value = 11;

        private  BigInteger TestProperty { get; set; }

        public  BigInteger TestProperty2 { get; set; } = 10;
        
        public static BigInteger TestProperty3
        {
            get => value;
            set { }
        }

above are test cases

@Jim8y Jim8y closed this as completed Nov 10, 2024
@Jim8y Jim8y reopened this Nov 11, 2024
@Jim8y
Copy link
Contributor Author

Jim8y commented Nov 11, 2024

Too complex to handle non-static property correctly, too many places need to be updated, and many of them actually did not handle static-non static property/field at all. It is very easy to make mistakes, better to ban defining non-static symbols in smart contract.

@Jim8y
Copy link
Contributor Author

Jim8y commented Nov 11, 2024

@shargon please consider. I can update analyzer to enforce this.

@shargon
Copy link
Member

shargon commented Nov 11, 2024

For me is good if we ban until is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants