Esempio n. 1
0
        public static bool ParameterListDiffers(IEnumerable <Type> _argsParent, IEnumerable <Type> _argsChild, ArgumentParameterSpecificity specificity = ArgumentParameterSpecificity.ArgumentMoreSpecific)
        {
            var argsParent = _argsParent.ToArray();
            var argsChild  = _argsChild.ToArray();

            if (argsChild.Length != argsParent.Length)
            {
                return(true);
            }

            for (var i = 0; i < argsChild.Length; ++i)
            {
                if (argsChild[i].FullName != argsParent[i].FullName)
                {
                    var typeParam = argsChild[i] as InheritableType;
                    var typeArg   = argsParent[i] as InheritableType;

                    if (typeParam == null || typeArg == null)
                    {
                        return(true);
                    }

                    var argInhParam = InheritableType.IsDescendantOf(typeParam, typeArg);
                    var paramInhArg = InheritableType.IsDescendantOf(typeArg, typeParam);

                    switch (specificity)
                    {
                    case ArgumentParameterSpecificity.ArgumentMoreSpecific: return(!argInhParam);

                    case ArgumentParameterSpecificity.ParameterMoreSpecific: return(!paramInhArg);

                    case ArgumentParameterSpecificity.Bidirectional: return(!(argInhParam || paramInhArg));
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Validates if all methods of an interface have been implemented.
        /// </summary>
        public static IEnumerable <Result> FulfillsInheritanceConstraints(InterfaceType interf, InheritableType derivedType)
        {
            yield return(ResultSense.FalseDominates);

            foreach (var(name, prototype) in interf.Scope.AllMembers)
            {
                Type member;
                if ((member = derivedType.Scope.GetSymbol(name)) != null)
                {
                    if (prototype is FunctionType)
                    {
                        if (member is not FunctionType)
                        {
                            yield return(Result.False);

                            yield return(new OverrideMemberTypeMismatchError(prototype, member, member.DefiningToken));
                        }
                        else
                        {
                            var res = FulfillsFunctionOverride(prototype as FunctionType, member as FunctionType);
                            if (res.HasErrors())
                            {
                                if (!res.BoolValue())
                                {
                                    yield return(Result.False);
                                }

                                foreach (var error in res.Errors())
                                {
                                    yield return(error);
                                }
                            }
                        }
                    }
                }
                else
                {
                    yield return(Result.False);

                    yield return(new OverrideMissingError(prototype, derivedType, derivedType.DefiningToken));
                }
            }
        }