Esempio n. 1
0
        static partial void ValidateObjectExtension(ref CoreLib.ValidationErrorsBuilder e, MethodSignature m)
        {
            if (m.Params.IsDefault)
            {
                e.AddErr("default(ImmutableArray<...>) is not allowed value", "params");
            }

            if (m.IsConstructor() && m.IsStatic)
            {
                e.Add(ValidationErrors.Create($"Constructor '{m}' can't be static").Nest("isStatic"));
            }
            if (m.IsStaticConstructor() && !m.IsStatic)
            {
                e.Add(ValidationErrors.Create($"Static constructor '{m}' must be static").Nest("isStatic"));
            }

            if (m.IsAbstract && m.DeclaringType?.IsAbstract == false)
            {
                e.Add(ValidationErrors.Create($"Can not declare abstract method in {m.DeclaringType}").Nest("isAbstract"));
            }
            if (m.IsAbstract && !m.IsVirtual)
            {
                e.Add(ValidationErrors.Create($"Can not declare abstract method that is not virtual").Nest("isVirtual"));
            }
            if (m.Accessibility == Accessibility.APrivate && (m.IsVirtual || m.IsOverride))
            {
                e.Add(ValidationErrors.Create($"Can not declare virtual or override method that is private").Nest("accessibility"));
            }
            if (m.IsStatic)
            {
                if (m.IsVirtual)
                {
                    e.Add(ValidationErrors.Create($"Can not declare virtual static method").Nest("isVirtual"));
                }
                if (m.IsOverride)
                {
                    e.Add(ValidationErrors.Create($"Can not declare override static method").Nest("isOverride"));
                }
                if (m.IsAbstract)
                {
                    e.Add(ValidationErrors.Create($"Can not declare abstract static method").Nest("isAbstract"));
                }
            }
            if (!m.DeclaringType.CanOverride)
            {
                if (m.IsVirtual)
                {
                    e.Add(ValidationErrors.Create($"Can not declare virtual method in {m.DeclaringType}").Nest("isVirtual"));
                }
                // if (m.IsOverride) e.Add(ValidationErrors.Create($"Can not declare override method in {m.DeclaringType}").Nest("isOverride"));
                if (m.IsAbstract)
                {
                    e.Add(ValidationErrors.Create($"Can not declare abstract method in {m.DeclaringType}").Nest("isAbstract"));
                }
                if (m.DeclaringType.IsAbstract && !m.IsStatic)
                {
                    e.Add(ValidationErrors.Create($"Can not declare non-stattic method in {m.DeclaringType}").Nest("isStatic"));
                }
            }
        }
Esempio n. 2
0
        static partial void ValidateObjectExtension(ref CoreLib.ValidationErrorsBuilder e, NumericConversionExpression n)
        {
            if (e.HasErrors)
            {
                return;
            }

            bool isNumericSignature(TypeSignature ts) =>
            ts == TypeSignature.Byte ||
            ts == TypeSignature.SByte ||
            ts == TypeSignature.Int16 ||
            ts == TypeSignature.UInt16 ||
            ts == TypeSignature.Int32 ||
            ts == TypeSignature.UInt32 ||
            ts == TypeSignature.Int64 ||
            ts == TypeSignature.UInt64 ||
            ts == TypeSignature.IntPtr ||
            ts == TypeSignature.UIntPtr ||
            ts == TypeSignature.Single ||
            ts == TypeSignature.Double;

            bool isNumericType(TypeReference t) =>
            t.Match(
                s => isNumericSignature(s.Type),
                array => false,
                byRef => false,
                ptr => true,
                generic => true,
                func => false);

            var from = n.Value.Type();
            var to   = n.Type;

            if (!isNumericType(from))
            {
                e.AddErr($"Can not apply numeric conversion on expression of type {from}", "value"); // TODO: expression type validation path
            }
            if (!isNumericType(to))
            {
                e.AddErr($"Can not use numeric conversion to convert to type {to}", "type");
            }
        }