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

Cannot intialize classes declared with parantheses (brackets) #1216

Open
Hecate2 opened this issue Oct 28, 2024 · 3 comments
Open

Cannot intialize classes declared with parantheses (brackets) #1216

Hecate2 opened this issue Oct 28, 2024 · 3 comments

Comments

@Hecate2
Copy link
Contributor

Hecate2 commented Oct 28, 2024

using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
using System;
using System.Numerics;
using Neo.SmartContract.Framework;

namespace Neo.Compiler.CSharp.TestContracts
{
    public class ClassWithDifferentTypes()  // delete the brackets () to compile successfully
    {
        public bool b;
        public char c;
        public int i;
        public string? s;
        public IntInit ii;
        public ClassWithDifferentTypes? cl;
    }

    public class Contract_ClassInit : SmartContract.Framework.SmartContract
    {
        public static ClassWithDifferentTypes TestInitializationExpression()
        {
            ClassWithDifferentTypes newCl = new() { s = "s", cl = new() };
            foreach (ClassWithDifferentTypes cl in new ClassWithDifferentTypes[] { newCl, newCl.cl })
            {
                ExecutionEngine.Assert(cl.b == default);
                ExecutionEngine.Assert(cl.c == default);
                ExecutionEngine.Assert(cl.i == default);
                ExecutionEngine.Assert(cl.s == "s");
                ExecutionEngine.Assert(cl.ii.A == default);
                ExecutionEngine.Assert(cl.ii.B == default);
            }
            return newCl;
        }
    }
}

Class declaration with parentheses in C# is probably allowed, but in our compiler it is recognized as a ClassDeclarationSyntax in a method, leading to an exception.

@shargon
Copy link
Member

shargon commented Oct 28, 2024

Primary constructors

@nan01ab
Copy link
Contributor

nan01ab commented Oct 29, 2024

there isn't any C# 12 feature support yet.

@Jim8y
Copy link
Contributor

Jim8y commented Oct 29, 2024

there isn't any C# 12 feature support yet.

many has being supported, but not this one..

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

No branches or pull requests

4 participants