all: replace `var` with `mut`

pull/4555/head
Kris Cherven 2020-04-22 19:16:58 -04:00 committed by GitHub
parent 4e1abc8503
commit d871595437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 113 additions and 113 deletions

View File

@ -74,7 +74,7 @@ fn main() {
eprintln('vfmt env_vflags_and_os_args: ' + args.str())
eprintln('vfmt possible_files: ' + possible_files.str())
}
var files := []string
mut files := []string
for file in possible_files {
if !file.ends_with('.v') && !file.ends_with('.vv') {
verror('v fmt can only be used on .v files.\nOffending file: "$file"')
@ -90,16 +90,16 @@ fn main() {
vhelp.show_topic('fmt')
exit(0)
}
var cli_args_no_files := []string
mut cli_args_no_files := []string
for a in os.args {
if !(a in files) {
cli_args_no_files << a
}
}
var errors := 0
mut errors := 0
for file in files {
fpath := os.real_path(file)
var worker_command_array := cli_args_no_files.clone()
mut worker_command_array := cli_args_no_files.clone()
worker_command_array << ['-worker', fpath]
worker_cmd := worker_command_array.join(' ')
if foptions.is_verbose {
@ -252,8 +252,8 @@ fn file_to_target_os(file string) string {
}
fn file_to_mod_name_and_is_module_file(file string) (string, bool) {
var mod_name := 'main'
var is_module_file := false
mut mod_name := 'main'
mut is_module_file := false
flines := read_source_lines(file) or {
return mod_name, is_module_file
}
@ -287,7 +287,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
all_files_in_pfolder := os.ls(pfolder) or {
panic(err)
}
var vfiles := []string
mut vfiles := []string
for f in all_files_in_pfolder {
vf := os.join_path(pfolder, f)
if f.starts_with('.') || !f.ends_with('.v') || os.is_dir(vf) {
@ -304,7 +304,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
// containing `fn main` then the folder contains multiple standalone
// v programs. If only one contains `fn main` then the folder is
// a project folder, that should be compiled with `v pfolder`.
var main_fns := 0
mut main_fns := 0
for f in vfiles {
slines := read_source_lines(f) or {
panic(err)

View File

@ -109,9 +109,9 @@ fn main() {
}
fn parse_args(args []string) (&pref.Preferences, string) {
var res := &pref.Preferences{}
var command := ''
var command_pos := 0
mut res := &pref.Preferences{}
mut command := ''
mut command_pos := 0
// for i, arg in args {
for i := 0; i < args.len; i++ {
arg := args[i]
@ -198,7 +198,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
i++
}
else {
var should_continue := false
mut should_continue := false
for flag_with_param in list_of_flags_with_param {
if '-$flag_with_param' == arg {
should_continue = true
@ -254,8 +254,8 @@ fn create_symlink() {
return
}
vexe := pref.vexe_path()
var link_path := '/usr/local/bin/v'
var ret := os.exec('ln -sf $vexe $link_path') or {
mut link_path := '/usr/local/bin/v'
mut ret := os.exec('ln -sf $vexe $link_path') or {
panic(err)
}
if ret.exit_code == 0 {

View File

@ -47,7 +47,7 @@ pub fn new_builder(pref &pref.Preferences) Builder {
// parse all deps from already parsed files
pub fn (b mut Builder) parse_imports() {
var done_imports := []string
mut done_imports := []string
// NB: b.parsed_files is appended in the loop,
// so we can not use the shorter `for in` form.
for i := 0; i < b.parsed_files.len; i++ {
@ -97,7 +97,7 @@ pub fn (b mut Builder) resolve_deps() {
eprintln(deps_resolved.display())
eprintln('------------------------------------------')
}
var mods := []string
mut mods := []string
for node in deps_resolved.nodes {
mods << node.name
}
@ -106,7 +106,7 @@ pub fn (b mut Builder) resolve_deps() {
eprintln(mods.str())
eprintln('-------------------------------')
}
var reordered_parsed_files := []ast.File
mut reordered_parsed_files := []ast.File
for m in mods {
for pf in b.parsed_files {
if m == pf.mod.name {
@ -120,11 +120,11 @@ pub fn (b mut Builder) resolve_deps() {
// graph of all imported modules
pub fn (b &Builder) import_graph() &depgraph.DepGraph {
var builtins := util.builtin_module_parts
mut builtins := util.builtin_module_parts
builtins << 'builtin'
var graph := depgraph.new_dep_graph()
mut graph := depgraph.new_dep_graph()
for p in b.parsed_files {
var deps := []string
mut deps := []string
if p.mod.name !in builtins {
deps << 'builtin'
}
@ -137,7 +137,7 @@ pub fn (b &Builder) import_graph() &depgraph.DepGraph {
}
pub fn (b Builder) v_files_from_dir(dir string) []string {
var res := []string
mut res := []string
if !os.exists(dir) {
if dir == 'compiler' && os.is_dir('vlib') {
println('looks like you are trying to build V with an old command')
@ -147,7 +147,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
} else if !os.is_dir(dir) {
verror("$dir isn't a directory!")
}
var files := os.ls(dir) or {
mut files := os.ls(dir) or {
panic(err)
}
if b.pref.is_verbose {
@ -168,7 +168,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
continue
}
if b.pref.compile_defines_all.len > 0 && file.contains('_d_') {
var allowed := false
mut allowed := false
for cdefine in b.pref.compile_defines {
file_postfix := '_d_${cdefine}.v'
if file.ends_with(file_postfix) {
@ -246,7 +246,7 @@ pub fn (b Builder) find_module_path(mod, fpath string) ?string {
// support @VROOT/v.mod relative paths:
vmod_file_location := vmod.mod_file_cacher.get(fpath)
mod_path := module_path(mod)
var module_lookup_paths := []string
mut module_lookup_paths := []string
if vmod_file_location.vmod_file.len != 0 && !(vmod_file_location.vmod_folder in b.module_search_paths) {
module_lookup_paths << vmod_file_location.vmod_folder
}

View File

@ -1947,7 +1947,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
} else {
g.writeln('($styp){')
}
// var fields := []string
// mut fields := []string
mut inited_fields := []string // TODO this is done in checker, move to ast node
/*
if struct_init.fields.len == 0 && struct_init.exprs.len > 0 {

View File

@ -8,7 +8,7 @@ fn test_x64() {
eprintln('x64 tests can only be run on Linux for now.')
exit(0)
}
var bench := benchmark.new_benchmark()
mut bench := benchmark.new_benchmark()
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
dir := os.join_path(vroot, 'vlib/v/gen/x64/tests')
@ -45,11 +45,11 @@ fn test_x64() {
eprintln(res.output)
continue
}
var expected := os.read_file('$dir/${test}.out') or {
mut expected := os.read_file('$dir/${test}.out') or {
panic(err)
}
expected = expected.trim_space().trim('\n').replace('\r\n', '\n')
var found := res.output.trim_space().trim('\n').replace('\r\n', '\n')
mut found := res.output.trim_space().trim('\n').replace('\r\n', '\n')
// remove ACK char TODO fix this in x64
buf := [byte(0x06)]
ack := string(buf)

View File

@ -7,7 +7,7 @@ import v.ast
import v.table
import v.token
fn (var p Parser) assign_stmt() ast.Stmt {
fn (mut p Parser) assign_stmt() ast.Stmt {
is_static := p.tok.kind == .key_static
if is_static {
p.next()
@ -51,7 +51,7 @@ fn (var p Parser) assign_stmt() ast.Stmt {
}
// TODO: is it possible to merge with AssignStmt?
pub fn (var p Parser) assign_expr(left ast.Expr) ast.AssignExpr {
pub fn (mut p Parser) assign_expr(left ast.Expr) ast.AssignExpr {
op := p.tok.kind
pos := p.tok.position()
p.next()
@ -72,8 +72,8 @@ pub fn (var p Parser) assign_expr(left ast.Expr) ast.AssignExpr {
return node
}
fn (var p Parser) parse_assign_lhs() []ast.Ident {
var idents := []ast.Ident
fn (mut p Parser) parse_assign_lhs() []ast.Ident {
mut idents := []ast.Ident
for {
is_mut := p.tok.kind == .key_mut || p.tok.kind == .key_var
if is_mut {
@ -83,7 +83,7 @@ fn (var p Parser) parse_assign_lhs() []ast.Ident {
if is_static {
p.check(.key_static)
}
var ident := p.parse_ident(false, false)
mut ident := p.parse_ident(false, false)
ident.is_mut = is_mut
ident.info = ast.IdentVar{
is_mut: is_mut
@ -100,8 +100,8 @@ fn (var p Parser) parse_assign_lhs() []ast.Ident {
}
// right hand side of `=` or `:=` in `a,b,c := 1,2,3`
fn (var p Parser) parse_assign_rhs() []ast.Expr {
var exprs := []ast.Expr
fn (mut p Parser) parse_assign_rhs() []ast.Expr {
mut exprs := []ast.Expr
for {
expr := p.expr(0)
exprs << expr

View File

@ -15,7 +15,7 @@ const (
)
// // #include, #flag, #v
fn (p mut Parser) hash() ast.HashStmt {
fn (mut p Parser) hash() ast.HashStmt {
val := p.tok.lit
p.next()
if val.starts_with('flag') {
@ -56,7 +56,7 @@ fn (p mut Parser) hash() ast.HashStmt {
}
}
fn (p mut Parser) comp_if() ast.CompIf {
fn (mut p Parser) comp_if() ast.CompIf {
pos := p.tok.position()
p.next()
p.check(.key_if)

View File

@ -7,15 +7,15 @@ import v.ast
import v.table
import v.token
fn (var p Parser) array_init() ast.ArrayInit {
fn (mut p Parser) array_init() ast.ArrayInit {
first_pos := p.tok.position()
var last_pos := token.Position{}
mut last_pos := token.Position{}
p.check(.lsbr)
// p.warn('array_init() exp=$p.expected_type')
var array_type := table.void_type
var elem_type := table.void_type
var exprs := []ast.Expr
var is_fixed := false
mut array_type := table.void_type
mut elem_type := table.void_type
mut exprs := []ast.Expr
mut is_fixed := false
if p.tok.kind == .rsbr {
// []typ => `[]` and `typ` must be on the same line
line_nr := p.tok.line_nr
@ -93,10 +93,10 @@ fn (var p Parser) array_init() ast.ArrayInit {
}
}
fn (var p Parser) map_init() ast.MapInit {
fn (mut p Parser) map_init() ast.MapInit {
pos := p.tok.position()
var keys := []ast.Expr
var vals := []ast.Expr
mut keys := []ast.Expr
mut vals := []ast.Expr
for p.tok.kind != .rcbr && p.tok.kind != .eof {
// p.check(.str)
key := p.expr(0)

View File

@ -7,7 +7,7 @@ import v.ast
import v.table
import v.token
fn (var p Parser) for_stmt() ast.Stmt {
fn (mut p Parser) for_stmt() ast.Stmt {
p.check(.key_for)
pos := p.tok.position()
p.open_scope()
@ -27,13 +27,13 @@ fn (var p Parser) for_stmt() ast.Stmt {
p.error('`var` is not needed in for loops')
} else if p.peek_tok.kind in [.decl_assign, .assign, .semicolon] || p.tok.kind == .semicolon {
// `for i := 0; i < 10; i++ {`
var init := ast.Stmt{}
var cond := p.new_true_expr()
mut init := ast.Stmt{}
mut cond := p.new_true_expr()
// mut inc := ast.Stmt{}
var inc := ast.Expr{}
var has_init := false
var has_cond := false
var has_inc := false
mut inc := ast.Expr{}
mut has_init := false
mut has_cond := false
mut has_inc := false
if p.peek_tok.kind in [.assign, .decl_assign] {
init = p.assign_stmt()
has_init = true
@ -67,8 +67,8 @@ fn (var p Parser) for_stmt() ast.Stmt {
}
} else if p.peek_tok.kind in [.key_in, .comma] {
// `for i in vals`, `for i in start .. end`
var key_var_name := ''
var val_var_name := p.check_name()
mut key_var_name := ''
mut val_var_name := p.check_name()
if p.tok.kind == .comma {
p.check(.comma)
key_var_name = val_var_name
@ -95,8 +95,8 @@ fn (var p Parser) for_stmt() ast.Stmt {
// 0 .. 10
// start := p.tok.lit.int()
// TODO use RangeExpr
var high_expr := ast.Expr{}
var is_range := false
mut high_expr := ast.Expr{}
mut is_range := false
if p.tok.kind == .dotdot {
is_range = true
p.check(.dotdot)

View File

@ -7,14 +7,14 @@ import v.ast
import v.table
import v.token
fn (var p Parser) if_expr() ast.IfExpr {
fn (mut p Parser) if_expr() ast.IfExpr {
pos := p.tok.position()
var branches := []ast.IfBranch
var has_else := false
mut branches := []ast.IfBranch
mut has_else := false
for p.tok.kind in [.key_if, .key_else] {
p.inside_if = true
branch_pos := p.tok.position()
var comment := ast.Comment{}
mut comment := ast.Comment{}
if p.tok.kind == .key_if {
p.check(.key_if)
} else {
@ -36,8 +36,8 @@ fn (var p Parser) if_expr() ast.IfExpr {
break
}
}
var cond := ast.Expr{}
var is_or := false
mut cond := ast.Expr{}
mut is_or := false
// `if x := opt() {`
if p.peek_tok.kind == .decl_assign {
is_or = true
@ -78,26 +78,26 @@ fn (var p Parser) if_expr() ast.IfExpr {
}
}
fn (var p Parser) match_expr() ast.MatchExpr {
fn (mut p Parser) match_expr() ast.MatchExpr {
match_first_pos := p.tok.position()
p.inside_match = true
p.check(.key_match)
is_mut := p.tok.kind in [.key_mut, .key_var]
var is_sum_type := false
mut is_sum_type := false
if is_mut {
p.next()
}
cond := p.expr(0)
p.inside_match = false
p.check(.lcbr)
var branches := []ast.MatchBranch
mut branches := []ast.MatchBranch
for {
branch_first_pos := p.tok.position()
comment := p.check_comment() // comment before {}
var exprs := []ast.Expr
mut exprs := []ast.Expr
p.open_scope()
// final else
var is_else := false
mut is_else := false
if p.tok.kind == .key_else {
is_else = true
p.next()
@ -111,7 +111,7 @@ fn (var p Parser) match_expr() ast.MatchExpr {
x := ast.Type{
typ: typ
}
var expr := ast.Expr{}
mut expr := ast.Expr{}
expr = x
exprs << expr
p.scope.register('it', ast.Var{
@ -125,7 +125,7 @@ fn (var p Parser) match_expr() ast.MatchExpr {
}
is_sum_type = true
// Make sure a variable used for the sum type match
var var_name := ''
mut var_name := ''
match cond {
ast.Ident {
var_name = it.name

View File

@ -5,7 +5,7 @@ module parser
// that can be found in the LICENSE file.
import v.table
pub fn (p mut Parser) parse_array_type() table.Type {
pub fn (mut p Parser) parse_array_type() table.Type {
p.check(.lsbr)
// fixed array
if p.tok.kind == .number {
@ -19,7 +19,7 @@ pub fn (p mut Parser) parse_array_type() table.Type {
// array
p.check(.rsbr)
elem_type := p.parse_type()
var nr_dims := 1
mut nr_dims := 1
for p.tok.kind == .lsbr {
p.check(.lsbr)
p.check(.rsbr)
@ -29,7 +29,7 @@ pub fn (p mut Parser) parse_array_type() table.Type {
return table.new_type(idx)
}
pub fn (p mut Parser) parse_map_type() table.Type {
pub fn (mut p Parser) parse_map_type() table.Type {
p.next()
if p.tok.kind != .lsbr {
return table.map_type
@ -47,9 +47,9 @@ pub fn (p mut Parser) parse_map_type() table.Type {
return table.new_type(idx)
}
pub fn (p mut Parser) parse_multi_return_type() table.Type {
pub fn (mut p Parser) parse_multi_return_type() table.Type {
p.check(.lpar)
var mr_types := []table.Type
mut mr_types := []table.Type
for {
mr_type := p.parse_type()
mr_types << mr_type
@ -65,12 +65,12 @@ pub fn (p mut Parser) parse_multi_return_type() table.Type {
}
// given anon name based off signature when `name` is blank
pub fn (p mut Parser) parse_fn_type(name string) table.Type {
pub fn (mut p Parser) parse_fn_type(name string) table.Type {
// p.warn('parse fn')
p.check(.key_fn)
line_nr := p.tok.line_nr
args, is_variadic := p.fn_args()
var return_type := table.void_type
mut return_type := table.void_type
if p.tok.line_nr == line_nr && p.tok.kind.is_start_of_type() {
return_type = p.parse_type()
}
@ -84,7 +84,7 @@ pub fn (p mut Parser) parse_fn_type(name string) table.Type {
return table.new_type(idx)
}
pub fn (p mut Parser) parse_type_with_mut(is_mut bool) table.Type {
pub fn (mut p Parser) parse_type_with_mut(is_mut bool) table.Type {
typ := p.parse_type()
if is_mut {
return table.type_set_nr_muls(typ, 1)
@ -92,14 +92,14 @@ pub fn (p mut Parser) parse_type_with_mut(is_mut bool) table.Type {
return typ
}
pub fn (p mut Parser) parse_type() table.Type {
pub fn (mut p Parser) parse_type() table.Type {
// optional
var is_optional := false
mut is_optional := false
if p.tok.kind == .question {
p.next()
is_optional = true
}
var nr_muls := 0
mut nr_muls := 0
if p.tok.kind == .key_mut {
nr_muls++
p.next()
@ -119,7 +119,7 @@ pub fn (p mut Parser) parse_type() table.Type {
p.next()
p.check(.dot)
}
var typ := p.parse_any_type(is_c, is_js, nr_muls > 0)
mut typ := p.parse_any_type(is_c, is_js, nr_muls > 0)
if is_optional {
typ = table.type_set(typ, .optional)
}
@ -129,8 +129,8 @@ pub fn (p mut Parser) parse_type() table.Type {
return typ
}
pub fn (p mut Parser) parse_any_type(is_c, is_js, is_ptr bool) table.Type {
var name := p.tok.lit
pub fn (mut p Parser) parse_any_type(is_c, is_js, is_ptr bool) table.Type {
mut name := p.tok.lit
if is_c {
name = 'C.$name'
} else if is_js {
@ -229,7 +229,7 @@ pub fn (p mut Parser) parse_any_type(is_c, is_js, is_ptr bool) table.Type {
else {
// struct / enum / placeholder
// struct / enum
var idx := p.table.find_type_idx(name)
mut idx := p.table.find_type_idx(name)
if idx > 0 {
return table.new_type(idx)
}

View File

@ -233,7 +233,7 @@ pub fn (mut p Parser) parse_block_no_scope() []ast.Stmt {
}
/*
fn (p mut Parser) next_with_comment() {
fn (mut p Parser) next_with_comment() {
p.tok = p.peek_tok
p.peek_tok = p.scanner.scan()
}
@ -501,7 +501,7 @@ fn (mut p Parser) attribute() ast.Attr {
}
/*
fn (p mut Parser) range_expr(low ast.Expr) ast.Expr {
fn (mut p Parser) range_expr(low ast.Expr) ast.Expr {
// ,table.Type) {
if p.tok.kind != .dotdot {
p.next()

View File

@ -17,15 +17,15 @@ fn (table &Table) has_cflag(flag cflag.CFlag) bool {
// parse the flags to (table.cflags) []CFlag
// Note: clean up big time (joe-c)
pub fn (var table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?bool {
pub fn (table mut Table) parse_cflag(cflg, mod string, ctimedefines []string) ?bool {
allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
flag_orig := cflg.trim_space()
var flag := flag_orig
mut flag := flag_orig
if flag == '' {
return none
}
var fos := ''
var allowed_os_overrides := ['linux', 'darwin', 'freebsd', 'windows', 'mingw', 'solaris']
mut fos := ''
mut allowed_os_overrides := ['linux', 'darwin', 'freebsd', 'windows', 'mingw', 'solaris']
allowed_os_overrides << ctimedefines
for os_override in allowed_os_overrides {
if !flag.starts_with(os_override) {
@ -38,8 +38,8 @@ pub fn (var table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?b
flag = flag[pos..].trim_space()
}
for {
var name := ''
var value := ''
mut name := ''
mut value := ''
if flag[0] == `-` {
for f in allowed_flags {
i := 1 + f.len
@ -50,11 +50,11 @@ pub fn (var table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?b
}
}
}
var index := flag.index(' -') or {
mut index := flag.index(' -') or {
-1
}
for index > -1 {
var has_next := false
mut has_next := false
for f in allowed_flags {
i := index + 2 + f.len
if i <= flag.len && f == flag[index + 2..i] {

View File

@ -45,14 +45,14 @@ mut:
}
pub fn new_table() &Table {
var t := &Table{}
mut t := &Table{}
t.register_builtin_type_symbols()
return t
}
// used to compare fn's & for naming anon fn's
pub fn (f &Fn) signature() string {
var sig := ''
mut sig := ''
for i, arg in f.args {
// TODO: for now ignore mut/pts in sig for now
typ := type_set_nr_muls(arg.typ, 0)
@ -85,12 +85,12 @@ pub fn (t &Table) known_fn(name string) bool {
return true
}
pub fn (var t Table) register_fn(new_fn Fn) {
pub fn (mut t Table) register_fn(new_fn Fn) {
// println('reg fn $new_fn.name nr_args=$new_fn.args.len')
t.fns[new_fn.name] = new_fn
}
pub fn (var t TypeSymbol) register_method(new_fn Fn) {
pub fn (mut t TypeSymbol) register_method(new_fn Fn) {
t.methods << new_fn
}
@ -142,7 +142,7 @@ pub fn (t &Table) type_has_method(s &TypeSymbol, name string) bool {
// search from current type up through each parent looking for method
pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
// println('type_find_method($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
var ts := s
mut ts := s
for {
if method := ts.find_method(name) {
return method
@ -166,7 +166,7 @@ pub fn (t &Table) struct_has_field(s &TypeSymbol, name string) bool {
// search from current type up through each parent looking for field
pub fn (t &Table) struct_find_field(s &TypeSymbol, name string) ?Field {
// println('struct_find_field($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
var ts := s
mut ts := s
for {
if field := ts.find_field(name) {
return field
@ -214,7 +214,7 @@ pub fn (t &Table) get_type_name(typ Type) string {
// allows prexisitng types added in register_builtins
// to be overriden with their real type info
[inline]
pub fn (var t Table) register_builtin_type_symbol(typ TypeSymbol) int {
pub fn (mut t Table) register_builtin_type_symbol(typ TypeSymbol) int {
existing_idx := t.type_idxs[typ.name]
if existing_idx > 0 {
if existing_idx >= string_type_idx {
@ -234,7 +234,7 @@ pub fn (var t Table) register_builtin_type_symbol(typ TypeSymbol) int {
}
[inline]
pub fn (var t Table) register_type_symbol(typ TypeSymbol) int {
pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
// println('register_type_symbol( $typ.name )')
existing_idx := t.type_idxs[typ.name]
if existing_idx > 0 {
@ -308,7 +308,7 @@ pub fn (t &Table) map_name(key_type, value_type Type) string {
// return 'map_${value_type_sym.name}' + suffix
}
pub fn (var t Table) find_or_register_map(key_type, value_type Type) int {
pub fn (mut t Table) find_or_register_map(key_type, value_type Type) int {
name := t.map_name(key_type, value_type)
// existing
existing_idx := t.type_idxs[name]
@ -328,7 +328,7 @@ pub fn (var t Table) find_or_register_map(key_type, value_type Type) int {
return t.register_type_symbol(map_typ)
}
pub fn (var t Table) find_or_register_array(elem_type Type, nr_dims int) int {
pub fn (mut t Table) find_or_register_array(elem_type Type, nr_dims int) int {
name := t.array_name(elem_type, nr_dims)
// existing
existing_idx := t.type_idxs[name]
@ -348,7 +348,7 @@ pub fn (var t Table) find_or_register_array(elem_type Type, nr_dims int) int {
return t.register_type_symbol(array_type)
}
pub fn (var t Table) find_or_register_array_fixed(elem_type Type, size, nr_dims int) int {
pub fn (mut t Table) find_or_register_array_fixed(elem_type Type, size, nr_dims int) int {
name := t.array_fixed_name(elem_type, size, nr_dims)
// existing
existing_idx := t.type_idxs[name]
@ -368,8 +368,8 @@ pub fn (var t Table) find_or_register_array_fixed(elem_type Type, size, nr_dims
return t.register_type_symbol(array_fixed_type)
}
pub fn (var t Table) find_or_register_multi_return(mr_typs []Type) int {
var name := 'multi_return'
pub fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int {
mut name := 'multi_return'
for mr_typ in mr_typs {
mr_type_sym := t.get_type_symbol(mr_typ)
name += '_$mr_type_sym.name'
@ -390,7 +390,7 @@ pub fn (var t Table) find_or_register_multi_return(mr_typs []Type) int {
return t.register_type_symbol(mr_type)
}
pub fn (var t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool) int {
pub fn (mut t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool) int {
name := if f.name.len == 0 { 'anon_fn_$f.signature()' } else { f.name }
return t.register_type_symbol(TypeSymbol{
kind: .function
@ -403,7 +403,7 @@ pub fn (var t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool)
})
}
pub fn (var t Table) add_placeholder_type(name string) int {
pub fn (mut t Table) add_placeholder_type(name string) int {
ph_type := TypeSymbol{
kind: .placeholder
name: name

View File

@ -9,8 +9,8 @@ pub fn (c Color) str() string {
}
fn test_match_integers() {
var a := 3
var b := 0
mut a := 3
mut b := 0
match a {
2 { println('two') }
3 {
@ -63,7 +63,7 @@ fn test_match_integers() {
}
fn test_match_enums() {
var b := Color.red
mut b := Color.red
match b {
.red { b = .green }
.green { b = .blue }