Skip to content

Commit e23835c

Browse files
authored
parser: cleanup name_expr (calculate is_capital_after_last_dot once) (#25623)
1 parent d362e65 commit e23835c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

vlib/v/parser/parser.v

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,16 +1649,17 @@ fn (mut p Parser) name_expr() ast.Expr {
16491649
name_w_mod := p.prepend_mod(name)
16501650
is_c_pointer_cast := language == .c && prev_tok_kind == .amp // `&C.abc(x)` is *always* a cast
16511651
is_c_type_cast := language == .c && (original_name in ['intptr_t', 'uintptr_t']
1652-
|| (name in p.table.type_idxs && original_name[0].is_capital()))
1653-
is_js_cast := language == .js && name.all_after_last('.')[0].is_capital()
1652+
|| (original_name[0].is_capital() && name in p.table.type_idxs))
1653+
is_capital_after_last_dot := name.all_after_last('.')[0].is_capital()
1654+
is_js_cast := language == .js && is_capital_after_last_dot
16541655
// type cast. TODO: finish
16551656
// if name in ast.builtin_type_names_to_idx {
16561657
// handle the easy cases first, then check for an already known V typename, not shadowed by a local variable
16571658
if (is_option || p.peek_tok.kind in [.lsbr, .lt, .lpar]) && (is_mod_cast
16581659
|| is_c_pointer_cast || is_c_type_cast || is_js_cast || is_generic_cast
1659-
|| (language == .v && name != '' && (name[0].is_capital() || (!known_var
1660-
&& (name in p.table.type_idxs || name_w_mod in p.table.type_idxs))
1661-
|| name.all_after_last('.')[0].is_capital()))) {
1660+
|| (language == .v && name != '' && (is_capital_after_last_dot
1661+
|| name[0].is_capital()
1662+
|| (!known_var && (name in p.table.type_idxs || name_w_mod in p.table.type_idxs))))) {
16621663
// MainLetter(x) is *always* a cast, as long as it is not `C.`
16631664
// TODO: handle C.stat()
16641665
start_pos := p.tok.pos()

0 commit comments

Comments
 (0)