@@ -2949,10 +2949,12 @@ compile_list(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
29492949/*
29502950 * parse a lambda: "{arg, arg -> expr}" or "(arg, arg) => expr"
29512951 * "*arg" points to the '{'.
2952+ * Returns OK/FAIL when a lambda is recognized, NOTDONE if it's not a lambda.
29522953 */
29532954 static int
29542955compile_lambda (char_u * * arg , cctx_T * cctx )
29552956{
2957+ int r ;
29562958 typval_T rettv ;
29572959 ufunc_T * ufunc ;
29582960 evalarg_T evalarg ;
@@ -2962,10 +2964,11 @@ compile_lambda(char_u **arg, cctx_T *cctx)
29622964 evalarg .eval_cctx = cctx ;
29632965
29642966 // Get the funcref in "rettv".
2965- if (get_lambda_tv (arg , & rettv , TRUE, & evalarg ) != OK )
2967+ r = get_lambda_tv (arg , & rettv , TRUE, & evalarg );
2968+ if (r != OK )
29662969 {
29672970 clear_evalarg (& evalarg , NULL );
2968- return FAIL ;
2971+ return r ;
29692972 }
29702973
29712974 // "rettv" will now be a partial referencing the function.
@@ -4001,26 +4004,13 @@ compile_expr7(
40014004 * Lambda: {arg, arg -> expr}
40024005 * Dictionary: {'key': val, 'key': val}
40034006 */
4004- case '{' : {
4005- char_u * start = skipwhite (* arg + 1 );
4006- char_u * after = start ;
4007- garray_T ga_arg ;
4008-
4009- // Find out what comes after the arguments.
4010- ret = get_function_args (& after , '-' , NULL ,
4011- & ga_arg , TRUE, NULL , NULL ,
4012- TRUE, NULL , NULL );
4013- if (ret != FAIL && after [0 ] == '>'
4014- && ((after > start + 2
4015- && VIM_ISWHITE (after [-2 ]))
4016- || after == start + 1 )
4017- && IS_WHITE_OR_NUL (after [1 ]))
4018- // TODO: if we go with the "(arg) => expr" syntax
4019- // remove this
4020- ret = compile_lambda (arg , cctx );
4021- else
4022- ret = compile_dict (arg , cctx , ppconst );
4023- }
4007+ case '{' : // Try parsing as a lambda, if NOTDONE is returned it
4008+ // must be a dict.
4009+ // TODO: if we go with the "(arg) => expr" syntax remove
4010+ // this
4011+ ret = compile_lambda (arg , cctx );
4012+ if (ret == NOTDONE )
4013+ ret = compile_dict (arg , cctx , ppconst );
40244014 break ;
40254015
40264016 /*
@@ -4051,32 +4041,10 @@ compile_expr7(
40514041 * lambda: (arg, arg) => expr
40524042 * funcref: (arg, arg) => { statement }
40534043 */
4054- case '(' : {
4055- char_u * start = skipwhite (* arg + 1 );
4056- char_u * after = start ;
4057- garray_T ga_arg ;
4058-
4059- // Find out if "=>" comes after the ().
4060- ret = get_function_args (& after , ')' , NULL ,
4061- & ga_arg , TRUE, NULL , NULL ,
4062- TRUE, NULL , NULL );
4063- if (ret == OK && VIM_ISWHITE (
4064- * after == ':' ? after [1 ] : * after ))
4065- {
4066- if (* after == ':' )
4067- // Skip over type in "(arg): type".
4068- after = skip_type (skipwhite (after + 1 ), TRUE);
4069-
4070- after = skipwhite (after );
4071- if (after [0 ] == '=' && after [1 ] == '>'
4072- && IS_WHITE_OR_NUL (after [2 ]))
4073- {
4074- ret = compile_lambda (arg , cctx );
4075- break ;
4076- }
4077- }
4044+ case '(' : // if compile_lambda returns NOTDONE then it must be (expr)
4045+ ret = compile_lambda (arg , cctx );
4046+ if (ret == NOTDONE )
40784047 ret = compile_parenthesis (arg , cctx , ppconst );
4079- }
40804048 break ;
40814049
40824050 default : ret = NOTDONE ;
0 commit comments