Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/wrong_struct_init_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vlib/v/checker/tests/wrong_struct_init_err.vv:4:33: error: struct name must begin with capital letter
2 |
3 | import net.http
4 | _ := http.Response{header: http.new_header{} }
| ~~~~~~~~~~
5 |
5 changes: 5 additions & 0 deletions vlib/v/checker/tests/wrong_struct_init_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module main

import net.http
_ := http.Response{header: http.new_header{} }

7 changes: 7 additions & 0 deletions vlib/v/parser/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ fn (mut p Parser) struct_init(typ_str string, kind ast.StructInitKind, is_option
first_pos := (if kind == .short_syntax && p.prev_tok.kind == .lcbr { p.prev_tok } else { p.tok }).pos()
p.init_generic_types = []ast.Type{}
mut typ := if kind == .short_syntax { ast.void_type } else { p.parse_type() }
sym := p.table.sym(typ)
struct_name := sym.name.all_after_last('.')
if sym.kind == .placeholder && struct_name.len > 0 && !struct_name[0].is_capital()
&& !sym.name.starts_with('C.') {
p.error_with_pos('struct name must begin with capital letter', first_pos)
return ast.StructInit{}
}
struct_init_generic_types := p.init_generic_types.clone()
if is_option {
typ = typ.set_flag(.option)
Expand Down
Loading