From 5db25352e54116c51f2db698880455785b78e1d7 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Mon, 16 Sep 2019 03:39:48 +1000 Subject: [PATCH] compiler: fix module typo detection --- compiler/table.v | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/table.v b/compiler/table.v index 0ed7e39ca7..8b723b9c82 100644 --- a/compiler/table.v +++ b/compiler/table.v @@ -881,8 +881,7 @@ fn (table &Table) identify_typo(name string, current_fn &Fn, fit &FileImportTabl fn (table &Table) find_misspelled_fn(name string, fit &FileImportTable, min_match f32) string { mut closest := f32(0) mut closest_fn := '' - is_main_fn := name.starts_with('main__') - n1 := if is_main_fn { name.right(6) } else { name } + n1 := if name.starts_with('main__') { name.right(6) } else { name } for _, f in table.fns { if n1.len - f.name.len > 2 || f.name.len - n1.len > 2 { continue } if !(f.mod in ['', 'main', 'builtin']) { @@ -908,10 +907,10 @@ fn (table &Table) find_misspelled_fn(name string, fit &FileImportTable, min_matc fn (table &Table) find_misspelled_imported_mod(name string, fit &FileImportTable, min_match f32) string { mut closest := f32(0) mut closest_mod := '' + n1 := if name.starts_with('main.') { name.right(5) } else { name } for alias, mod in fit.imports { - n := '${fit.module_name}.$alias' - if !name.starts_with(fit.module_name) || (n.len - name.len > 2 || name.len - n.len > 2) { continue } - p := strings.dice_coefficient(name, n) + if (n1.len - alias.len > 2 || alias.len - n1.len > 2) { continue } + p := strings.dice_coefficient(n1, alias) if p > closest { closest = p closest_mod = '$alias ($mod)'