Mercurial > vim
comparison src/vim9compile.c @ 24614:07b3d21a8b4b v8.2.2846
patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Commit: https://github.com/vim/vim/commit/68db996b621b98066fb7ab7028ed5c6aaa3954a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 9 23:19:22 2021 +0200
patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Problem: Vim9: "echo Func()" does not give an error for a function without
a return value.
Solution: Give an error. Be more specific about why a value is invalid.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 May 2021 23:30:05 +0200 |
parents | cb031f421ece |
children | 4a4f64cdc798 |
comparison
equal
deleted
inserted
replaced
24613:2ccff0c26a2f | 24614:07b3d21a8b4b |
---|---|
8373 static char_u * | 8373 static char_u * |
8374 compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx) | 8374 compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx) |
8375 { | 8375 { |
8376 char_u *p = arg; | 8376 char_u *p = arg; |
8377 char_u *prev = arg; | 8377 char_u *prev = arg; |
8378 char_u *expr_start; | |
8378 int count = 0; | 8379 int count = 0; |
8379 int start_ctx_lnum = cctx->ctx_lnum; | 8380 int start_ctx_lnum = cctx->ctx_lnum; |
8381 garray_T *stack = &cctx->ctx_type_stack; | |
8382 type_T *type; | |
8380 | 8383 |
8381 for (;;) | 8384 for (;;) |
8382 { | 8385 { |
8383 if (ends_excmd2(prev, p)) | 8386 if (ends_excmd2(prev, p)) |
8384 break; | 8387 break; |
8388 expr_start = p; | |
8385 if (compile_expr0(&p, cctx) == FAIL) | 8389 if (compile_expr0(&p, cctx) == FAIL) |
8386 return NULL; | 8390 return NULL; |
8391 | |
8392 if (cctx->ctx_skip != SKIP_YES) | |
8393 { | |
8394 // check for non-void type | |
8395 type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; | |
8396 if (type->tt_type == VAR_VOID) | |
8397 { | |
8398 semsg(_(e_expression_does_not_result_in_value_str), expr_start); | |
8399 return NULL; | |
8400 } | |
8401 } | |
8402 | |
8387 ++count; | 8403 ++count; |
8388 prev = p; | 8404 prev = p; |
8389 p = skipwhite(p); | 8405 p = skipwhite(p); |
8390 } | 8406 } |
8391 | 8407 |