コード例 #1
0
        protected override IType ValidateExpr(Environment env)
        {
            using var _ = env.Scopes.Use();

            if (Handle != null)
            {
                Handle.Bind(env);
            }

            ParameterList.Validate(env);

            Body.Validate(env);

            var returnType = Body.Type;

            // If parameter list has an explicit return type annotation
            var annotatedReturnTypeNode = ParameterList.ReturnType;

            if (annotatedReturnTypeNode != null)
            {
                var annotatedReturnType = annotatedReturnTypeNode.EvalType(env);
                Body.AssertType(annotatedReturnType);
                returnType = annotatedReturnType;
            }

            var result = new FunctionType()
            {
                IsLambda       = IsLambda,
                ReturnType     = returnType,
                ParameterTypes = ParameterList.EvaluatedNamePairs.Select(x => x.Item2).ToList(),
                ParameterNames = ParameterList.EvaluatedNamePairs.Select(x => x.Item1).ToList(),
            };

            return(Handle != null ? new GenericFunctionWrapper(result, Handle.Names.ToList()) : result);
        }