To: vim_dev@googlegroups.com Subject: Patch 9.0.1179 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1179 Problem: Not all errors around inheritance are tested. Solution: Add more tests. Fix uncovered problems. Files: src/vim9expr.c, src/vim9compile.c, src/errors.h, src/testdir/test_vim9_class.vim *** ../vim-9.0.1178/src/vim9expr.c 2023-01-11 15:59:01.175405240 +0000 --- src/vim9expr.c 2023-01-11 17:44:15.145607859 +0000 *************** *** 268,281 **** if (type == &t_super) { if (cctx->ctx_ufunc == NULL || cctx->ctx_ufunc->uf_class == NULL) - emsg(_(e_using_super_not_in_class_function)); - else { ! is_super = TRUE; ! cl = cctx->ctx_ufunc->uf_class; ! // Remove &t_super from the stack. ! --cctx->ctx_type_stack.ga_len; } } else if (type->tt_type == VAR_CLASS) { --- 268,281 ---- if (type == &t_super) { if (cctx->ctx_ufunc == NULL || cctx->ctx_ufunc->uf_class == NULL) { ! emsg(_(e_using_super_not_in_class_function)); ! return FAIL; } + is_super = TRUE; + cl = cctx->ctx_ufunc->uf_class; + // Remove &t_super from the stack. + --cctx->ctx_type_stack.ga_len; } else if (type->tt_type == VAR_CLASS) { *************** *** 2261,2266 **** --- 2261,2267 ---- // class constructor: SomeClass.new() // object member: someObject.varname, this.varname // object method: someObject.SomeMethod(), this.SomeMethod() + *arg = p; if (compile_class_object_index(cctx, arg, type) == FAIL) return FAIL; } *** ../vim-9.0.1178/src/vim9compile.c 2023-01-11 15:59:01.175405240 +0000 --- src/vim9compile.c 2023-01-11 17:47:12.981868019 +0000 *************** *** 49,54 **** --- 49,68 ---- && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW))) { int is_super = *name == 's'; + if (is_super) + { + if (name[5] != '.') + { + emsg(_(e_super_must_be_followed_by_dot)); + return FAIL; + } + if (cctx->ctx_ufunc->uf_class != NULL + && cctx->ctx_ufunc->uf_class->class_extends == NULL) + { + emsg(_(e_using_super_not_in_child_class)); + return FAIL; + } + } if (lvar != NULL) { CLEAR_POINTER(lvar); *** ../vim-9.0.1178/src/errors.h 2023-01-11 15:59:01.175405240 +0000 --- src/errors.h 2023-01-11 17:47:04.781857302 +0000 *************** *** 3438,3441 **** --- 3438,3443 ---- INIT(= N_("E1356: \"super\" must be followed by a dot")); EXTERN char e_using_super_not_in_class_function[] INIT(= N_("E1357: Using \"super\" not in a class function")); + EXTERN char e_using_super_not_in_child_class[] + INIT(= N_("E1358: Using \"super\" not in a child class")); #endif *** ../vim-9.0.1178/src/testdir/test_vim9_class.vim 2023-01-11 15:59:01.175405240 +0000 --- src/testdir/test_vim9_class.vim 2023-01-11 17:54:55.530339186 +0000 *************** *** 838,843 **** --- 838,900 ---- assert_equal('John: 42', o.ToString()) END v9.CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + class Child + this.age: number + def ToString(): number + return this.age + enddef + def ToString(): string + return this.age + enddef + endclass + END + v9.CheckScriptFailure(lines, 'E1355: Duplicate function: ToString') + + lines =<< trim END + vim9script + class Child + this.age: number + def ToString(): string + return super .ToString() .. ': ' .. this.age + enddef + endclass + var o = Child.new(42) + echo o.ToString() + END + v9.CheckScriptFailure(lines, 'E1356:') + + lines =<< trim END + vim9script + class Base + this.name: string + def ToString(): string + return this.name + enddef + endclass + + var age = 42 + def ToString(): string + return super.ToString() .. ': ' .. age + enddef + echo ToString() + END + v9.CheckScriptFailure(lines, 'E1357:') + + lines =<< trim END + vim9script + class Child + this.age: number + def ToString(): string + return super.ToString() .. ': ' .. this.age + enddef + endclass + var o = Child.new(42) + echo o.ToString() + END + v9.CheckScriptFailure(lines, 'E1358:') enddef *** ../vim-9.0.1178/src/version.c 2023-01-11 15:59:01.179405247 +0000 --- src/version.c 2023-01-11 17:19:20.187997015 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1179, /**/ -- For humans, honesty is a matter of degree. Engineers are always honest in matters of technology and human relationships. That's why it's a good idea to keep engineers away from customers, romantic interests, and other people who can't handle the truth. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///