@@ -4377,8 +4377,10 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
43774377 }
43784378 }
43794379 }
4380- c.error (util.new_suggestion (node.name, const_names_in_mod).say ('undefined ident: `${node .name }`' ),
4381- node.pos)
4380+ c.check_known_struct_name (node) or {
4381+ c.error (util.new_suggestion (node.name, const_names_in_mod).say ('undefined ident: `${node .name }`' ),
4382+ node.pos)
4383+ }
43824384 } else {
43834385 // If a variable is not found in the scope of an anonymous function
43844386 // but is in an external scope, then we can suggest the user add it to the capturing list.
@@ -4398,13 +4400,32 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
43984400 }
43994401 }
44004402
4401- c.error ('undefined ident: `${node .name }`' , node.pos)
4403+ c.check_known_struct_name (node) or {
4404+ c.error ('undefined ident: `${node .name }`' , node.pos)
4405+ }
44024406 }
44034407 }
44044408 }
44054409 return ast.void_type
44064410}
44074411
4412+ fn (mut c Checker) check_known_struct_name (ident ast.Ident) ? {
4413+ mut is_struct := false
4414+ if ident.mod == 'builtin' || ident.mod == 'main' {
4415+ is_struct = c.table.find_type (ident.name) != 0
4416+ if ! is_struct {
4417+ is_struct = c.table.find_type ('main.${ident .name }' ) != 0
4418+ }
4419+ } else {
4420+ is_struct = c.table.find_type ('${ident .mod }.${ident .name }' ) != 0
4421+ }
4422+ if is_struct {
4423+ c.error ('`${ident .name }` must be initialized' , ident.pos)
4424+ return
4425+ }
4426+ return none
4427+ }
4428+
44084429fn (mut c Checker) concat_expr (mut node ast.ConcatExpr) ast.Type {
44094430 mut mr_types := []ast.Type{}
44104431 for mut expr in node.vals {
0 commit comments