static partial void ValidateObjectExtension(ref ValidationErrorsBuilder e, PropertySignature p) { if (p.Getter is null && p.Setter is null) { e.AddErr("Getter or setter must specified", "getter"); e.AddErr("Setter or getter must specified", "setter"); } if (p.Getter is object) { if (!p.Getter.Params.IsEmpty) { e.AddErr("Getter must have no parameters", "getter", "params"); } } }
static partial void ValidateObjectExtension(ref ValidationErrorsBuilder e, MethodParameter p) { if (p.Type == TypeSignature.Void) { e.AddErr($"Method parameter must not have a type void.", "type"); } }
static partial void ValidateObjectExtension(ref ValidationErrorsBuilder e, MethodDef obj) { if (obj.Implements.IsDefault) { e.AddErr("default(ImmutableArray<...>) is not allowed value", "implements"); } var sgn = obj.Signature; if (obj.Body is object && obj.Body.Type() != sgn.ResultType) { e.Add(ValidationErrors.Create($"Method body was expected to return {sgn.ResultType}, not {obj.Body.Type()}").Nest("body")); // TODO: expression type validation } var isWithoutBody = obj.Signature.IsAbstract || obj.Signature.DeclaringType.Kind == "interface"; if (obj.Body is null && !isWithoutBody) { e.Add(ValidationErrors.Create($"Method is not abstract, so it must contain a body.")); } if (obj.Body is object && isWithoutBody) { e.Add(ValidationErrors.Create($"Method is abstract, so it must not contain a body. Did you intent to use MethodDef.InterfaceDef?")); } if (!isWithoutBody) { if (obj.ArgumentParams.IsDefault) { e.AddErr("default(ImmutableArray<...>) is not allowed value", "argumentParams"); } var expectedArgs = obj.Signature.Params.Select(p => p.Type).ToImmutableArray(); if (!sgn.IsStatic) { expectedArgs = expectedArgs.Insert(0, sgn.DeclaringType.SpecializeByItself()); } if (obj.ArgumentParams.Length != expectedArgs.Length) { e.Add(ValidationErrors.Create($"Expected {expectedArgs.Length} arguments, got {obj.ArgumentParams.Length}: {FmtToken.FormatArray(obj.ArgumentParams)}").Nest("length").Nest("argumentParams")); } for (int i = 0; i < Math.Min(obj.ArgumentParams.Length, expectedArgs.Length); i++) { if (obj.ArgumentParams[i].Type.UnwrapReference() != expectedArgs[i].UnwrapReference()) { e.Add(ValidationErrors.Create($"Argument type {expectedArgs[i]} was expected instead of {obj.ArgumentParams[i].Type}.") .Nest("type").Nest(i.ToString()).Nest("argumentParams") ); } } if (!sgn.IsStatic) { var firstArgument = obj.ArgumentParams.First(); if (sgn.DeclaringType.IsValueType) { if (TypeReference.ByReferenceType(sgn.DeclaringType.SpecializeByItself()) != firstArgument.Type) { e.AddErr($"Method on value type should have this of a reference type: {firstArgument.Type}&", "argumentParams", "0", "type"); } } } } // TODO: deep validate expression in the context }