comparison runtime/doc/vim9.txt @ 21715:571832713efa v8.2.1407

patch 8.2.1407: Vim9: type of list and dict only depends on first item Commit: https://github.com/vim/vim/commit/127542bcebeb6480493b09d75a3be1d98a5f7797 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 9 17:22:04 2020 +0200 patch 8.2.1407: Vim9: type of list and dict only depends on first item Problem: Vim9: type of list and dict only depends on first item. Solution: Use all items to decide about the type.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Aug 2020 17:30:03 +0200
parents 1b345fb68ae3
children ef3b31d510d2
comparison
equal deleted inserted replaced
21714:e5d6e27da443 21715:571832713efa
617 and/or a dictionary, which are not visible to the caller. Since they are 617 and/or a dictionary, which are not visible to the caller. Since they are
618 called in the same way the declaration is the same. 618 called in the same way the declaration is the same.
619 619
620 Custom types can be defined with `:type`: > 620 Custom types can be defined with `:type`: >
621 :type MyList list<string> 621 :type MyList list<string>
622 Custom types must start with a capital letter, to avoid name clashes with
623 builtin types added later, similarly to user functions.
622 {not implemented yet} 624 {not implemented yet}
623 625
624 And classes and interfaces can be used as types: > 626 And classes and interfaces can be used as types: >
625 :class MyClass 627 :class MyClass
626 :let mine: MyClass 628 :let mine: MyClass
643 In general: Whenever the type is clear it can be omitted. For example, when 645 In general: Whenever the type is clear it can be omitted. For example, when
644 declaring a variable and giving it a value: > 646 declaring a variable and giving it a value: >
645 let var = 0 " infers number type 647 let var = 0 " infers number type
646 let var = 'hello' " infers string type 648 let var = 'hello' " infers string type
647 649
650 The type of a list and dictionary comes from the common type of the values.
651 If the values all have the same type, that type is used for the list or
652 dictionary. If there is a mix of types, the "any" type is used. >
653 [1, 2, 3] list<number>
654 ['a', 'b', 'c'] list<string>
655 [1, 'x', 3] list<any>
648 656
649 ============================================================================== 657 ==============================================================================
650 658
651 5. Namespace, Import and Export 659 5. Namespace, Import and Export
652 *vim9script* *vim9-export* *vim9-import* 660 *vim9script* *vim9-export* *vim9-import*