neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

Cannot intialize classes declared with parantheses (brackets)

Open Hecate2 opened this issue 1 year ago • 3 comments

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.

Hecate2 avatar Oct 28 '24 04:10 Hecate2

Primary constructors

shargon avatar Oct 28 '24 07:10 shargon

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

nan01ab avatar Oct 29 '24 12:10 nan01ab

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

many has being supported, but not this one..

Jim8y avatar Oct 29 '24 16:10 Jim8y