code: func newFunctionImpl(ctx sessionctx.Context, fold bool, funcName string, retType *types.FieldType, args ...Expression) (Expression, error) {
  	if retType == nil {
  		return nil, errors.Errorf("RetType cannot be nil for ScalarFunction.")
  	}
  	if funcName == ast.Cast {
  		return BuildCastFunction(ctx, args[0], retType), nil
  	}
  	fc, ok := funcs[funcName]
  	if !ok {
  		return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", funcName)
  	}
  	funcArgs := make([]Expression, len(args))
  	copy(funcArgs, args)
  	f, err := fc.getFunction(ctx, funcArgs)
  	if err != nil {
  		return nil, err
  	}
  	if builtinRetTp := f.getRetTp(); builtinRetTp.Tp != mysql.TypeUnspecified || retType.Tp == mysql.TypeUnspecified {
  		retType = builtinRetTp
  	}
  	sf := &ScalarFunction{
  		FuncName: model.NewCIStr(funcName),
  		RetType:  retType,
  		Function: f,
  	}
  	if fold {
  		return FoldConstant(sf), nil
  	}
  	return sf, nil
  }
docs: // newFunctionImpl creates a new scalar function or constant.