Mercurial > vim
comparison src/vim9compile.c @ 23428:5807e3958e38 v8.2.2257
patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Commit: https://github.com/vim/vim/commit/2949cfdbe4335b9abcfeda1be4dfc52090ee1df6
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 31 21:28:47 2020 +0100
patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Problem: Vim9: using -> for lambda is ambiguous.
Solution: Stop supporting ->, must use =>.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 31 Dec 2020 21:30:03 +0100 |
parents | bb0c53f4ef8b |
children | ab163feb30cb |
comparison
equal
deleted
inserted
replaced
23427:8f2dcc0cfcf6 | 23428:5807e3958e38 |
---|---|
2936 ppconst->pp_is_const = is_all_const; | 2936 ppconst->pp_is_const = is_all_const; |
2937 return generate_NEWLIST(cctx, count); | 2937 return generate_NEWLIST(cctx, count); |
2938 } | 2938 } |
2939 | 2939 |
2940 /* | 2940 /* |
2941 * parse a lambda: "{arg, arg -> expr}" or "(arg, arg) => expr" | 2941 * Parse a lambda: "(arg, arg) => expr" |
2942 * "*arg" points to the '{'. | 2942 * "*arg" points to the '{'. |
2943 * Returns OK/FAIL when a lambda is recognized, NOTDONE if it's not a lambda. | 2943 * Returns OK/FAIL when a lambda is recognized, NOTDONE if it's not a lambda. |
2944 */ | 2944 */ |
2945 static int | 2945 static int |
2946 compile_lambda(char_u **arg, cctx_T *cctx) | 2946 compile_lambda(char_u **arg, cctx_T *cctx) |
2983 return generate_FUNCREF(cctx, ufunc); | 2983 return generate_FUNCREF(cctx, ufunc); |
2984 } | 2984 } |
2985 | 2985 |
2986 func_ptr_unref(ufunc); | 2986 func_ptr_unref(ufunc); |
2987 return FAIL; | 2987 return FAIL; |
2988 } | |
2989 | |
2990 /* | |
2991 * Compile a lamda call: expr->{lambda}(args) | |
2992 * "arg" points to the "{". | |
2993 */ | |
2994 static int | |
2995 compile_lambda_call(char_u **arg, cctx_T *cctx) | |
2996 { | |
2997 ufunc_T *ufunc; | |
2998 typval_T rettv; | |
2999 int argcount = 1; | |
3000 int ret = FAIL; | |
3001 | |
3002 // Get the funcref in "rettv". | |
3003 if (get_lambda_tv(arg, &rettv, TRUE, &EVALARG_EVALUATE) == FAIL) | |
3004 return FAIL; | |
3005 | |
3006 if (**arg != '(') | |
3007 { | |
3008 if (*skipwhite(*arg) == '(') | |
3009 emsg(_(e_nowhitespace)); | |
3010 else | |
3011 semsg(_(e_missing_paren), "lambda"); | |
3012 clear_tv(&rettv); | |
3013 return FAIL; | |
3014 } | |
3015 | |
3016 ufunc = rettv.vval.v_partial->pt_func; | |
3017 ++ufunc->uf_refcount; | |
3018 clear_tv(&rettv); | |
3019 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); | |
3020 | |
3021 // The function will have one line: "return {expr}". Compile it into | |
3022 // instructions so that we get any errors right now. | |
3023 compile_def_function(ufunc, TRUE, cctx); | |
3024 | |
3025 // compile the arguments | |
3026 *arg = skipwhite(*arg + 1); | |
3027 if (compile_arguments(arg, cctx, &argcount) == OK) | |
3028 // call the compiled function | |
3029 ret = generate_CALL(cctx, ufunc, argcount); | |
3030 | |
3031 if (ret == FAIL) | |
3032 func_ptr_unref(ufunc); | |
3033 return ret; | |
3034 } | 2988 } |
3035 | 2989 |
3036 /* | 2990 /* |
3037 * parse a dict: {key: val, [key]: val} | 2991 * parse a dict: {key: val, [key]: val} |
3038 * "*arg" points to the '{'. | 2992 * "*arg" points to the '{'. |
3600 return FAIL; | 3554 return FAIL; |
3601 | 3555 |
3602 p += 2; | 3556 p += 2; |
3603 *arg = skipwhite(p); | 3557 *arg = skipwhite(p); |
3604 // No line break supported right after "->". | 3558 // No line break supported right after "->". |
3605 if (**arg == '{') | 3559 if (**arg == '(') |
3606 { | |
3607 // lambda call: list->{lambda} | |
3608 // TODO: remove this | |
3609 if (compile_lambda_call(arg, cctx) == FAIL) | |
3610 return FAIL; | |
3611 } | |
3612 else if (**arg == '(') | |
3613 { | 3560 { |
3614 int argcount = 1; | 3561 int argcount = 1; |
3615 char_u *expr; | 3562 char_u *expr; |
3616 garray_T *stack; | 3563 garray_T *stack; |
3617 type_T *type; | 3564 type_T *type; |
3629 return FAIL; | 3576 return FAIL; |
3630 } | 3577 } |
3631 ++*arg; | 3578 ++*arg; |
3632 if (**arg != '(') | 3579 if (**arg != '(') |
3633 { | 3580 { |
3634 semsg(_(e_missing_paren), *arg); | 3581 if (*skipwhite(*arg) == '(') |
3582 emsg(_(e_nowhitespace)); | |
3583 else | |
3584 semsg(_(e_missing_paren), *arg); | |
3635 return FAIL; | 3585 return FAIL; |
3636 } | 3586 } |
3637 | 3587 |
3638 *arg = skipwhite(*arg + 1); | 3588 *arg = skipwhite(*arg + 1); |
3639 if (compile_arguments(arg, cctx, &argcount) == FAIL) | 3589 if (compile_arguments(arg, cctx, &argcount) == FAIL) |
4003 */ | 3953 */ |
4004 case '[': ret = compile_list(arg, cctx, ppconst); | 3954 case '[': ret = compile_list(arg, cctx, ppconst); |
4005 break; | 3955 break; |
4006 | 3956 |
4007 /* | 3957 /* |
4008 * Lambda: {arg, arg -> expr} | |
4009 * Dictionary: {'key': val, 'key': val} | 3958 * Dictionary: {'key': val, 'key': val} |
4010 */ | 3959 */ |
4011 case '{': // Try parsing as a lambda, if NOTDONE is returned it | 3960 case '{': ret = compile_dict(arg, cctx, ppconst); |
4012 // must be a dict. | |
4013 // TODO: if we go with the "(arg) => expr" syntax remove | |
4014 // this | |
4015 ret = compile_lambda(arg, cctx); | |
4016 if (ret == NOTDONE) | |
4017 ret = compile_dict(arg, cctx, ppconst); | |
4018 break; | 3961 break; |
4019 | 3962 |
4020 /* | 3963 /* |
4021 * Option value: &name | 3964 * Option value: &name |
4022 */ | 3965 */ |