@@ -49,14 +49,13 @@ pub mut:
49
49
error_lines []int // to avoid printing multiple errors for the same line
50
50
expected_type ast.Type
51
51
expected_or_type ast.Type // fn() or { 'this type' } eg. string. expected or block type
52
- // cur_fn &ast.FnDecl // current function
53
- const_decl string
54
- const_deps []string
55
- const_names []string
56
- global_names []string
57
- locked_names []string // vars that are currently locked
58
- rlocked_names []string // vars that are currently read-locked
59
- in_for_count int // if checker is currently in a for loop
52
+ const_decl string
53
+ const_deps []string
54
+ const_names []string
55
+ global_names []string
56
+ locked_names []string // vars that are currently locked
57
+ rlocked_names []string // vars that are currently read-locked
58
+ in_for_count int // if checker is currently in a for loop
60
59
// checked_ident string // to avoid infinite checker loops
61
60
returns bool
62
61
scope_returns bool
82
81
timers & util.Timers = util.new_timers (false )
83
82
comptime_fields_type map [string ]ast.Type
84
83
fn_scope & ast.Scope = voidptr (0 )
85
- cur_concrete_types []ast.Type // current concrete types, e.g. <int, string>
86
84
main_fn_decl_node ast.FnDecl
87
85
match_exhaustive_cutoff_limit int = 10
88
86
// TODO: these are here temporarily and used for deprecations; remove soon
@@ -689,7 +687,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) ast.Type {
689
687
struct_sym := c.table.get_type_symbol (struct_init.typ)
690
688
if struct_sym.info is ast.Struct {
691
689
if struct_sym.info.generic_types.len > 0 && struct_sym.info.concrete_types.len == 0
692
- && c.cur_concrete_types.len == 0 {
690
+ && c.table. cur_concrete_types.len == 0 {
693
691
c.error ('generic struct init must specify type parameter, e.g. Foo<int>' ,
694
692
struct_init.pos)
695
693
}
@@ -704,7 +702,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) ast.Type {
704
702
return ast.void_type
705
703
}
706
704
}
707
- utyp := c.unwrap_generic_struct (struct_init.typ, c.table.cur_fn.generic_names, c.cur_concrete_types)
705
+ utyp := c.unwrap_generic_struct (struct_init.typ, c.table.cur_fn.generic_names, c.table. cur_concrete_types)
708
706
c.ensure_type_exists (utyp, struct_init.pos) or {}
709
707
type_sym := c.table.get_type_symbol (utyp)
710
708
if ! c.inside_unsafe && type_sym.kind == .sum_type {
@@ -713,7 +711,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) ast.Type {
713
711
// Make sure the first letter is capital, do not allow e.g. `x := string{}`,
714
712
// but `x := T{}` is ok.
715
713
if ! c.is_builtin_mod && ! c.inside_unsafe && type_sym.language == .v
716
- && c.cur_concrete_types.len == 0 {
714
+ && c.table. cur_concrete_types.len == 0 {
717
715
pos := type_sym.name.last_index ('.' ) or { - 1 }
718
716
first_letter := type_sym.name[pos + 1 ]
719
717
if ! first_letter.is_capital () {
@@ -2220,7 +2218,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
2220
2218
concrete_types << concrete_type
2221
2219
}
2222
2220
}
2223
- if ! isnil (c.table.cur_fn) && c.cur_concrete_types.len == 0 && has_generic {
2221
+ if ! isnil (c.table.cur_fn) && c.table. cur_concrete_types.len == 0 && has_generic {
2224
2222
c.error ('generic fn using generic types cannot be called outside of generic fn' ,
2225
2223
call_expr.pos)
2226
2224
}
@@ -2981,7 +2979,7 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) {
2981
2979
mut expected_type := c.unwrap_generic (c.expected_type)
2982
2980
if expected_type.has_flag (.generic) && c.table.get_type_symbol (expected_type).kind == .struct_ {
2983
2981
if t_typ := c.table.resolve_generic_to_concrete (expected_type, c.table.cur_fn.generic_names,
2984
- c.cur_concrete_types, true )
2982
+ c.table. cur_concrete_types, true )
2985
2983
{
2986
2984
expected_type = t_typ
2987
2985
}
@@ -3004,7 +3002,7 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) {
3004
3002
mut expected_types := [expected_type]
3005
3003
if expected_type_sym.info is ast.MultiReturn {
3006
3004
expected_types = expected_type_sym.info.types
3007
- if c.cur_concrete_types.len > 0 {
3005
+ if c.table. cur_concrete_types.len > 0 {
3008
3006
expected_types = expected_types.map (c.unwrap_generic (it ))
3009
3007
}
3010
3008
}
@@ -4561,7 +4559,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
4561
4559
pub fn (mut c Checker) unwrap_generic (typ ast.Type) ast.Type {
4562
4560
if typ.has_flag (.generic) {
4563
4561
if t_typ := c.table.resolve_generic_to_concrete (typ, c.table.cur_fn.generic_names,
4564
- c.cur_concrete_types, false )
4562
+ c.table. cur_concrete_types, false )
4565
4563
{
4566
4564
return t_typ
4567
4565
}
@@ -7063,7 +7061,7 @@ fn (mut c Checker) post_process_generic_fns() {
7063
7061
mut node := c.file.generic_fns[i]
7064
7062
c.mod = node.mod
7065
7063
for concrete_types in c.table.fn_generic_types[node.name] {
7066
- c.cur_concrete_types = concrete_types
7064
+ c.table. cur_concrete_types = concrete_types
7067
7065
c.fn_decl (mut node)
7068
7066
if node.name == 'vweb.run' {
7069
7067
for ct in concrete_types {
@@ -7073,13 +7071,13 @@ fn (mut c Checker) post_process_generic_fns() {
7073
7071
}
7074
7072
}
7075
7073
}
7076
- c.cur_concrete_types = []
7074
+ c.table. cur_concrete_types = []
7077
7075
}
7078
7076
}
7079
7077
7080
7078
fn (mut c Checker) fn_decl (mut node ast.FnDecl) {
7081
7079
c.returns = false
7082
- if node.generic_names.len > 0 && c.cur_concrete_types.len == 0 {
7080
+ if node.generic_names.len > 0 && c.table. cur_concrete_types.len == 0 {
7083
7081
// Just remember the generic function for now.
7084
7082
// It will be processed later in c.post_process_generic_fns,
7085
7083
// after all other normal functions are processed.
0 commit comments