Ejemplo n.º 1
0
        protected override void VisitStructInitializerSyntax(StructInitializerSyntax pNode)
        {
            //Check if the type exists
            if (pNode.Struct.Type == SmallTypeCache.Undefined)
            {
                CompilerErrors.UndeclaredType(pNode.Struct.ToString(), pNode.Span);
            }
            //Check if the type is a trait
            else if (pNode.Struct.Type.IsTrait)
            {
                CompilerErrors.AttemptDeclareTrait(pNode.Struct.Type, pNode.Span);
            }
            //Ensure the constructor arguments
            else if (pNode.Struct.Type.HasDefinedConstructor())
            {
                var m = pNode.Struct.Type.GetConstructor();
                for (int i = 0; i < m.ArgumentTypes.Count; i++)
                {
                    if (!CanCast(pNode.Arguments[i].Type, m.ArgumentTypes[i]))
                    {
                        CompilerErrors.TypeCastError(pNode.Arguments[i].Type, m.ArgumentTypes[i], pNode.Arguments[i].Span);
                    }
                }
            }

            base.VisitStructInitializerSyntax(pNode);
        }