END
v9.CheckSourceFailure(lines, 'E1335: Variable "val4" in class "C" is not writable')
- # TODO: the following tests use type "any" for argument. Need a run time
- # check for access. Probably OK as is for now.
-
# read-only lockvar from object method arg
lines =<< trim END
vim9script
class C
var val5: number
- def Lock(o_any: any)
- lockvar o_any.val5
+ def Lock(c: C)
+ lockvar c.val5
enddef
endclass
var o = C.new(3)
o.Lock(C.new(5))
END
- v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"')
+ v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val5" in class "C"')
# read-only lockvar from class method arg
lines =<< trim END
class C
var val6: number
- static def Lock(o_any: any)
- lockvar o_any.val6
+ static def Lock(c: C)
+ lockvar c.val6
enddef
endclass
var o = C.new(3)
C.Lock(o)
END
- v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"')
+ v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val6" in class "C"')
#
# lockvar of public object variable
class C
public var val5: number
- def Lock(o_any: any)
- lockvar o_any.val5
+ def Lock(c: C)
+ lockvar c.val5
enddef
endclass
var o = C.new(3)
o.Lock(C.new(5))
END
- v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"', 1)
+ v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val5" in class "C"', 1)
# lockvar from class method arg
lines =<< trim END
class C
public var val6: number
- static def Lock(o_any: any)
- lockvar o_any.val6
+ static def Lock(c: C)
+ lockvar c.val6
enddef
endclass
var o = C.new(3)
C.Lock(o)
END
- v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"', 1)
+ v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "c.val6" in class "C"', 1)
enddef
" Test trying to lock a class variable from various places
cstack->cs_flags[i] |= CSF_FUNC_DEF;
}
+/*
+ * Skip over all the characters in a single quoted string starting at "p" and
+ * return a pointer to the character following the ending single quote.
+ * If the ending single quote is missing, then return a pointer to the NUL
+ * character.
+ */
+ static char_u *
+skip_single_quote_string(char_u *p)
+{
+ p++; // skip the beginning single quote
+ while (*p != NUL)
+ {
+ // Within the string, a single quote can be escaped by using
+ // two single quotes.
+ if (*p == '\'' && *(p + 1) == '\'')
+ p += 2;
+ else if (*p == '\'')
+ {
+ p++; // skip the ending single quote
+ break;
+ }
+ else
+ MB_PTR_ADV(p);
+ }
+
+ return p;
+}
+
+/*
+ * Skip over all the characters in a double quoted string starting at "p" and
+ * return a pointer to the character following the ending double quote.
+ * If the ending double quote is missing, then return a pointer to the NUL
+ * character.
+ */
+ static char_u *
+skip_double_quote_string(char_u *p)
+{
+ p++; // skip the beginning double quote
+ while (*p != NUL)
+ {
+ // Within the string, a double quote can be escaped by
+ // preceding it with a backslash.
+ if (*p == '\\' && *(p + 1) == '"')
+ p += 2;
+ else if (*p == '"')
+ {
+ p++; // skip the ending double quote
+ break;
+ }
+ else
+ MB_PTR_ADV(p);
+ }
+
+ return p;
+}
+
+/*
+ * Return the start of a Vim9 comment (#) in the line starting at "line".
+ * If a comment is not found, then returns a pointer to the end of the
+ * string (NUL).
+ */
+ static char_u *
+find_start_of_vim9_comment(char_u *line)
+{
+ char_u *p = line;
+
+ while (*p != NUL)
+ {
+ if (*p == '\'')
+ // Skip a single quoted string.
+ p = skip_single_quote_string(p);
+ else if (*p == '"')
+ // Skip a double quoted string.
+ p = skip_double_quote_string(p);
+ else
+ {
+ if (*p == '#')
+ // Found the start of a Vim9 comment
+ break;
+ MB_PTR_ADV(p);
+ }
+ }
+
+ return p;
+}
+
/*
* Read the body of a function, put every line in "newlines".
* This stops at "}", "endfunction" or "enddef".
if (nesting_def[nesting] ? *p != '#' : *p != '"')
{
// Not a comment line: check for nested inline function.
- end = p + STRLEN(p) - 1;
+
+ if (nesting_inline[nesting])
+ {
+ // A comment (#) can follow the opening curly brace of a
+ // block statement. Need to ignore the comment and look
+ // for the opening curly brace before the comment.
+ end = find_start_of_vim9_comment(p) - 1;
+ }
+ else
+ end = p + STRLEN(p) - 1;
+
while (end > p && VIM_ISWHITE(*end))
--end;
if (end > p + 1 && *end == '{' && VIM_ISWHITE(end[-1]))