Exemple #1
0
        protected override IType ValidateExpr(Environment env)
        {
            EnsureValidBinding(env);

            if (!(Binding.Type is IFunctionType func))
            {
                throw new TranspilationException($"Cannot invoke non-invokable '{Name}'", Location);
            }

            AssertParameterCount(func);

            Exprs.ForEach(expr => expr.Validate(env));

            if (func is GenericFunctionWrapper wrapper)
            {
                func = SpecifyFunc(wrapper, env);
            }
            else if (Handle != null)
            {
                throw new TranspilationException($"Cannot specify generic types for non-generic function '{Name}'.", Location);
            }

            foreach (var(expr, type) in Exprs.Zip(func.ParameterTypes))
            {
                expr.AssertType(type);
            }

            // We re-assign the name such that it will be converted properly
            Name = Binding?.Name ?? Name;

            return(func.ReturnType);
        }