Mercurial > vim
comparison src/testdir/test_vim9_class.vim @ 31645:fc259e8db5bf v9.0.1155
patch 9.0.1155: cannot use a class as a type
Commit: https://github.com/vim/vim/commit/eca2c5fff6f6ccad0df8824c4b4354d3f410d225
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 7 12:08:41 2023 +0000
patch 9.0.1155: cannot use a class as a type
Problem: Cannot use a class as a type.
Solution: Accept a class and interface name as a type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 07 Jan 2023 13:15:04 +0100 |
parents | 62237ea155d9 |
children | 520857d1fda7 |
comparison
equal
deleted
inserted
replaced
31644:28fadea19672 | 31645:fc259e8db5bf |
---|---|
663 endclass | 663 endclass |
664 END | 664 END |
665 v9.CheckScriptFailure(lines, 'E1349: Function "Methods" of interface "Some" not implemented') | 665 v9.CheckScriptFailure(lines, 'E1349: Function "Methods" of interface "Some" not implemented') |
666 enddef | 666 enddef |
667 | 667 |
668 def Test_class_used_as_type() | |
669 var lines =<< trim END | |
670 vim9script | |
671 | |
672 class Point | |
673 this.x = 0 | |
674 this.y = 0 | |
675 endclass | |
676 | |
677 var p: Point | |
678 p = Point.new(2, 33) | |
679 assert_equal(2, p.x) | |
680 assert_equal(33, p.y) | |
681 END | |
682 v9.CheckScriptSuccess(lines) | |
683 | |
684 lines =<< trim END | |
685 vim9script | |
686 | |
687 interface HasX | |
688 this.x: number | |
689 endinterface | |
690 | |
691 class Point implements HasX | |
692 this.x = 0 | |
693 this.y = 0 | |
694 endclass | |
695 | |
696 var p: Point | |
697 p = Point.new(2, 33) | |
698 var hx = p | |
699 assert_equal(2, hx.x) | |
700 END | |
701 v9.CheckScriptSuccess(lines) | |
702 | |
703 lines =<< trim END | |
704 vim9script | |
705 | |
706 class Point | |
707 this.x = 0 | |
708 this.y = 0 | |
709 endclass | |
710 | |
711 var p: Point | |
712 p = 'text' | |
713 END | |
714 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object but got string') | |
715 enddef | |
716 | |
668 | 717 |
669 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 718 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |