comparison src/vim9cmds.c @ 32903:54c01bb98b8e v9.0.1760

patch 9.0.1760: vim9 class problem with new() constructor Commit: https://github.com/vim/vim/commit/6ac1544e13d78e0deeca1f357d1d73947180171c Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Aug 20 18:20:17 2023 +0200 patch 9.0.1760: vim9 class problem with new() constructor Problem: vim9 class problem with new() constructor Solution: Don't allow a return type for the new() class constructor. closes: #12863 closes: #12040 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 18:30:05 +0200
parents a39314fa9495
children 6340c608ca54
comparison
equal deleted inserted replaced
32902:d96544a100e3 32903:54c01bb98b8e
2615 { 2615 {
2616 emsg(_(e_missing_return_value)); 2616 emsg(_(e_missing_return_value));
2617 return NULL; 2617 return NULL;
2618 } 2618 }
2619 2619
2620 // No argument, return zero. 2620 if (cctx->ctx_ufunc->uf_flags & FC_NEW)
2621 generate_PUSHNR(cctx, 0); 2621 {
2622 // For a class new() constructor, return an object of the class.
2623 generate_instr(cctx, ISN_RETURN_OBJECT);
2624 cctx->ctx_ufunc->uf_ret_type =
2625 &cctx->ctx_ufunc->uf_class->class_object_type;
2626 }
2627 else
2628 // No argument, return zero.
2629 generate_PUSHNR(cctx, 0);
2622 } 2630 }
2623 2631
2624 // may need ENDLOOP when inside a :for or :while loop 2632 // may need ENDLOOP when inside a :for or :while loop
2625 if (compile_find_scope(NULL, NULL, NULL, NULL, cctx) == FAIL) 2633 if (compile_find_scope(NULL, NULL, NULL, NULL, cctx) == FAIL)
2626 2634