comparison src/vim9compile.c @ 19583:ba35daca6553 v8.2.0348

patch 8.2.0348: Vim9: not all code tested Commit: https://github.com/vim/vim/commit/5381c7a1628eeca81a46b811158be4cd47ba5815 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 2 22:53:32 2020 +0100 patch 8.2.0348: Vim9: not all code tested Problem: Vim9: not all code tested. Solution: Add a few more tests. fix using "b:" in literal dictionary.
author Bram Moolenaar <Bram@vim.org>
date Mon, 02 Mar 2020 23:00:06 +0100
parents aae19dd172c0
children e61dc51ab9b4
comparison
equal deleted inserted replaced
19582:1aac86ea0cd9 19583:ba35daca6553
505 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL 505 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL
506 && exptype != EXPR_IS && exptype != EXPR_ISNOT 506 && exptype != EXPR_IS && exptype != EXPR_ISNOT
507 && (type1 == VAR_BLOB || type2 == VAR_BLOB 507 && (type1 == VAR_BLOB || type2 == VAR_BLOB
508 || type1 == VAR_LIST || type2 == VAR_LIST)))) 508 || type1 == VAR_LIST || type2 == VAR_LIST))))
509 { 509 {
510 semsg(_("E1037: Cannot compare %s with %s"), 510 semsg(_("E1072: Cannot compare %s with %s"),
511 vartype_name(type1), vartype_name(type2)); 511 vartype_name(type1), vartype_name(type2));
512 return FAIL; 512 return FAIL;
513 } 513 }
514 514
515 if ((isn = generate_instr(cctx, isntype)) == NULL) 515 if ((isn = generate_instr(cctx, isntype)) == NULL)
1492 char * 1492 char *
1493 vartype_name(vartype_T type) 1493 vartype_name(vartype_T type)
1494 { 1494 {
1495 switch (type) 1495 switch (type)
1496 { 1496 {
1497 case VAR_UNKNOWN: break;
1497 case VAR_VOID: return "void"; 1498 case VAR_VOID: return "void";
1498 case VAR_UNKNOWN: return "any";
1499 case VAR_SPECIAL: return "special"; 1499 case VAR_SPECIAL: return "special";
1500 case VAR_BOOL: return "bool"; 1500 case VAR_BOOL: return "bool";
1501 case VAR_NUMBER: return "number"; 1501 case VAR_NUMBER: return "number";
1502 case VAR_FLOAT: return "float"; 1502 case VAR_FLOAT: return "float";
1503 case VAR_STRING: return "string"; 1503 case VAR_STRING: return "string";
1507 case VAR_LIST: return "list"; 1507 case VAR_LIST: return "list";
1508 case VAR_DICT: return "dict"; 1508 case VAR_DICT: return "dict";
1509 case VAR_FUNC: return "func"; 1509 case VAR_FUNC: return "func";
1510 case VAR_PARTIAL: return "partial"; 1510 case VAR_PARTIAL: return "partial";
1511 } 1511 }
1512 return "???"; 1512 return "any";
1513 } 1513 }
1514 1514
1515 /* 1515 /*
1516 * Return the name of a type. 1516 * Return the name of a type.
1517 * The result may be in allocated memory, in which case "tofree" is set. 1517 * The result may be in allocated memory, in which case "tofree" is set.
1905 #define VIM9_NAMESPACE_CHAR (char_u *)"bgstvw" 1905 #define VIM9_NAMESPACE_CHAR (char_u *)"bgstvw"
1906 1906
1907 /* 1907 /*
1908 * Find the end of a variable or function name. Unlike find_name_end() this 1908 * Find the end of a variable or function name. Unlike find_name_end() this
1909 * does not recognize magic braces. 1909 * does not recognize magic braces.
1910 * When "namespace" is TRUE recognize "b:", "s:", etc.
1910 * Return a pointer to just after the name. Equal to "arg" if there is no 1911 * Return a pointer to just after the name. Equal to "arg" if there is no
1911 * valid name. 1912 * valid name.
1912 */ 1913 */
1913 char_u * 1914 static char_u *
1914 to_name_end(char_u *arg) 1915 to_name_end(char_u *arg, int namespace)
1915 { 1916 {
1916 char_u *p; 1917 char_u *p;
1917 1918
1918 // Quick check for valid starting character. 1919 // Quick check for valid starting character.
1919 if (!eval_isnamec1(*arg)) 1920 if (!eval_isnamec1(*arg))
1921 1922
1922 for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p)) 1923 for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
1923 // Include a namespace such as "s:var" and "v:var". But "n:" is not 1924 // Include a namespace such as "s:var" and "v:var". But "n:" is not
1924 // and can be used in slice "[n:]". 1925 // and can be used in slice "[n:]".
1925 if (*p == ':' && (p != arg + 1 1926 if (*p == ':' && (p != arg + 1
1927 || !namespace
1926 || vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL)) 1928 || vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL))
1927 break; 1929 break;
1928 return p; 1930 return p;
1929 } 1931 }
1930 1932
1932 * Like to_name_end() but also skip over a list or dict constant. 1934 * Like to_name_end() but also skip over a list or dict constant.
1933 */ 1935 */
1934 char_u * 1936 char_u *
1935 to_name_const_end(char_u *arg) 1937 to_name_const_end(char_u *arg)
1936 { 1938 {
1937 char_u *p = to_name_end(arg); 1939 char_u *p = to_name_end(arg, TRUE);
1938 typval_T rettv; 1940 typval_T rettv;
1939 1941
1940 if (p == arg && *arg == '[') 1942 if (p == arg && *arg == '[')
1941 { 1943 {
1942 1944
2143 { 2145 {
2144 char_u *key = NULL; 2146 char_u *key = NULL;
2145 2147
2146 if (literal) 2148 if (literal)
2147 { 2149 {
2148 char_u *p = to_name_end(*arg); 2150 char_u *p = to_name_end(*arg, !literal);
2149 2151
2150 if (p == *arg) 2152 if (p == *arg)
2151 { 2153 {
2152 semsg(_("E1014: Invalid key: %s"), *arg); 2154 semsg(_("E1014: Invalid key: %s"), *arg);
2153 return FAIL; 2155 return FAIL;
2764 semsg(_("E1015: Name expected: %s"), *arg); 2766 semsg(_("E1015: Name expected: %s"), *arg);
2765 return FAIL; 2767 return FAIL;
2766 } 2768 }
2767 2769
2768 // "name" or "name()" 2770 // "name" or "name()"
2769 p = to_name_end(*arg); 2771 p = to_name_end(*arg, TRUE);
2770 if (*p == '(') 2772 if (*p == '(')
2771 r = compile_call(arg, p - *arg, cctx, 0); 2773 r = compile_call(arg, p - *arg, cctx, 0);
2772 else 2774 else
2773 r = compile_load(arg, p, cctx, TRUE); 2775 r = compile_load(arg, p, cctx, TRUE);
2774 if (r == FAIL) 2776 if (r == FAIL)
4978 // Assuming the command starts with a variable or function name, 4980 // Assuming the command starts with a variable or function name,
4979 // find what follows. Also "&opt = val", "$ENV = val" and "@r = 4981 // find what follows. Also "&opt = val", "$ENV = val" and "@r =
4980 // val". 4982 // val".
4981 p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@') 4983 p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
4982 ? ea.cmd + 1 : ea.cmd; 4984 ? ea.cmd + 1 : ea.cmd;
4983 p = to_name_end(p); 4985 p = to_name_end(p, TRUE);
4984 if ((p > ea.cmd && *p != NUL) || *p == '(') 4986 if ((p > ea.cmd && *p != NUL) || *p == '(')
4985 { 4987 {
4986 int oplen; 4988 int oplen;
4987 int heredoc; 4989 int heredoc;
4988 4990
4990 if (oplen > 0) 4992 if (oplen > 0)
4991 { 4993 {
4992 // Recognize an assignment if we recognize the variable 4994 // Recognize an assignment if we recognize the variable
4993 // name: 4995 // name:
4994 // "g:var = expr" 4996 // "g:var = expr"
4995 // "var = expr" where "var" is a local var name. 4997 // "local = expr" where "local" is a local var.
4998 // "script = expr" where "script" is a script-local var.
4999 // "import = expr" where "import" is an imported var
4996 // "&opt = expr" 5000 // "&opt = expr"
4997 // "$ENV = expr" 5001 // "$ENV = expr"
4998 // "@r = expr" 5002 // "@r = expr"
4999 if (*ea.cmd == '&' 5003 if (*ea.cmd == '&'
5000 || *ea.cmd == '$' 5004 || *ea.cmd == '$'