Пример #1
0
        public static void ValidateReferenceAssociatedReference(this IEntity entity, ComputationContext ctx)
        {
            IEntityInstance eval = entity.Evaluation.Components;

            if (ctx.Env.IsReferenceOfType(eval))
            {
                return;
            }

            ctx.Env.Dereferenced(eval, out eval);

            if (eval.EnumerateAll().Any(it => it.TargetType.Modifier.HasAssociatedReference))
            {
                ctx.AddError(ErrorCode.AssociatedReferenceRequiresPassingByReference, entity);
            }
        }
Пример #2
0
        private static bool interchangeableTypesTo(ComputationContext ctx, IEntityInstance input, IEntityInstance target)
        {
            bool is_input_sealed = input.EnumerateAll()
                                   .Select(it => { ctx.Env.Dereference(it, out IEntityInstance result); return(result); })
                                   .SelectMany(it => it.EnumerateAll())
                                   .All(it => it.Target.Modifier.IsSealed);

            if (is_input_sealed)
            {
                TypeMatch match = input.MatchesTarget(ctx, target, TypeMatching.Create(ctx.Env.Options.InterfaceDuckTyping, allowSlicing: true).WithIgnoredMutability(true));

                // example: we cannot check if x (of Int) is IAlien because Int is sealed and there is no way
                // it could be something else not available in its inheritance tree
                if (!match.Passed)
                {
                    return(false);
                }
            }

            return(true);
        }