mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
parser: fix case of falsely registering imports as used, remove unused imports (#21156)
This commit is contained in:
parent
59a5a790c9
commit
9704a01406
22 changed files with 100 additions and 104 deletions
|
@ -1,7 +1,6 @@
|
||||||
module anim
|
module anim
|
||||||
|
|
||||||
import benchmark
|
import benchmark
|
||||||
import sim
|
|
||||||
import sim.img
|
import sim.img
|
||||||
|
|
||||||
fn pixels_worker(mut app App) {
|
fn pixels_worker(mut app App) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import sokol
|
|
||||||
import sokol.sapp
|
import sokol.sapp
|
||||||
import sokol.gfx
|
import sokol.gfx
|
||||||
import sokol.sgl
|
import sokol.sgl
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import sokol
|
|
||||||
import sokol.sapp
|
import sokol.sapp
|
||||||
import sokol.gfx
|
import sokol.gfx
|
||||||
import sokol.sgl
|
import sokol.sgl
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
module gg
|
module gg
|
||||||
|
|
||||||
import gx
|
import gx
|
||||||
import sokol
|
|
||||||
import sokol.sgl
|
|
||||||
import math
|
import math
|
||||||
|
import sokol.sgl
|
||||||
|
|
||||||
// draw_pixel draws one pixel on the screen.
|
// draw_pixel draws one pixel on the screen.
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,7 +6,6 @@ module gg
|
||||||
import os
|
import os
|
||||||
import os.font
|
import os.font
|
||||||
import gx
|
import gx
|
||||||
import sokol
|
|
||||||
import sokol.sapp
|
import sokol.sapp
|
||||||
import sokol.sgl
|
import sokol.sgl
|
||||||
import sokol.gfx
|
import sokol.gfx
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
module big
|
module big
|
||||||
|
|
||||||
import math
|
|
||||||
import math.bits
|
import math.bits
|
||||||
|
|
||||||
// suppose operand_a bigger than operand_b and both not null.
|
// suppose operand_a bigger than operand_b and both not null.
|
||||||
|
|
|
@ -2,7 +2,6 @@ module cbuilder
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import sync
|
|
||||||
import v.util
|
import v.util
|
||||||
import v.builder
|
import v.builder
|
||||||
import sync.pool
|
import sync.pool
|
||||||
|
|
|
@ -6,7 +6,6 @@ module builder
|
||||||
import os
|
import os
|
||||||
import v.pref
|
import v.pref
|
||||||
import v.util
|
import v.util
|
||||||
import v.checker
|
|
||||||
|
|
||||||
pub type FnBackend = fn (mut b Builder)
|
pub type FnBackend = fn (mut b Builder)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ module builder
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import v.pref
|
|
||||||
import v.util
|
import v.util
|
||||||
import v.cflag
|
import v.cflag
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
|
|
||||||
// TODO: 600 line function
|
// TODO: 600 line function
|
||||||
fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
import v.util
|
import v.util
|
||||||
import v.token
|
import v.token
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
import v.token
|
import v.token
|
||||||
|
|
||||||
fn (mut c Checker) check_compatible_types(left_type ast.Type, right ast.TypeNode) ComptimeBranchSkipState {
|
fn (mut c Checker) check_compatible_types(left_type ast.Type, right ast.TypeNode) ComptimeBranchSkipState {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
import v.token
|
import v.token
|
||||||
|
|
||||||
fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
module checker
|
module checker
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
|
|
||||||
// error_type_name returns a proper type name reference for error messages
|
// error_type_name returns a proper type name reference for error messages
|
||||||
// ? => Option type
|
// ? => Option type
|
||||||
|
|
|
@ -1,98 +1,98 @@
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: mismatched types `Aaa` and `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:4:13: error: mismatched types `Aaa` and `int literal`
|
||||||
3 | struct Aaa{}
|
2 | struct Aaa{}
|
||||||
4 | fn main() {
|
3 | fn main() {
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:4:13: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
|
||||||
3 | struct Aaa{}
|
2 | struct Aaa{}
|
||||||
4 | fn main() {
|
3 | fn main() {
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:13: error: mismatched types `int literal` and `Aaa`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: mismatched types `int literal` and `Aaa`
|
||||||
4 | fn main() {
|
3 | fn main() {
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:13: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
|
||||||
4 | fn main() {
|
3 | fn main() {
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: mismatched types `[]int` and `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:13: error: mismatched types `[]int` and `int literal`
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: infix expr: cannot use `int literal` (right expression) as `[]int`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:13: error: infix expr: cannot use `int literal` (right expression) as `[]int`
|
||||||
5 | println(Aaa{} * 10)
|
4 | println(Aaa{} * 10)
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:13: error: mismatched types `int literal` and `[]int`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: mismatched types `int literal` and `[]int`
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:13: error: infix expr: cannot use `[]int` (right expression) as `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: infix expr: cannot use `[]int` (right expression) as `int literal`
|
||||||
6 | println(10 * Aaa{})
|
5 | println(10 * Aaa{})
|
||||||
7 | println([1,2,3] * 10)
|
6 | println([1,2,3] * 10)
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: mismatched types `map[string]int` and `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:9:13: error: mismatched types `map[string]int` and `int literal`
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
11 | println(10 * a)
|
10 | println(10 * a)
|
||||||
12 | c1 := cmplx.complex(1,-2)
|
11 | c1 := cmplx.complex(1,-2)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: infix expr: cannot use `int literal` (right expression) as `map[string]int`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:9:13: error: infix expr: cannot use `int literal` (right expression) as `map[string]int`
|
||||||
8 | println(10 * [1,2,3])
|
7 | println(10 * [1,2,3])
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
11 | println(10 * a)
|
10 | println(10 * a)
|
||||||
12 | c1 := cmplx.complex(1,-2)
|
11 | c1 := cmplx.complex(1,-2)
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:13: error: mismatched types `int literal` and `map[string]int`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: mismatched types `int literal` and `map[string]int`
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
11 | println(10 * a)
|
10 | println(10 * a)
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
12 | c1 := cmplx.complex(1,-2)
|
11 | c1 := cmplx.complex(1,-2)
|
||||||
13 | c2 := c1 * 2.0
|
12 | c2 := c1 * 2.0
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:13: error: infix expr: cannot use `map[string]int` (right expression) as `int literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: infix expr: cannot use `map[string]int` (right expression) as `int literal`
|
||||||
9 | a := map[string]int
|
8 | a := map[string]int
|
||||||
10 | println(a * 10)
|
9 | println(a * 10)
|
||||||
11 | println(10 * a)
|
10 | println(10 * a)
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
12 | c1 := cmplx.complex(1,-2)
|
11 | c1 := cmplx.complex(1,-2)
|
||||||
13 | c2 := c1 * 2.0
|
12 | c2 := c1 * 2.0
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:13:8: error: infix expr: cannot use `float literal` (right expression) as `math.complex.Complex`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:12:8: error: infix expr: cannot use `float literal` (right expression) as `math.complex.Complex`
|
||||||
11 | println(10 * a)
|
10 | println(10 * a)
|
||||||
12 | c1 := cmplx.complex(1,-2)
|
11 | c1 := cmplx.complex(1,-2)
|
||||||
13 | c2 := c1 * 2.0
|
12 | c2 := c1 * 2.0
|
||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
14 | println(c2)
|
13 | println(c2)
|
||||||
15 | c3 := 2.0 * c1
|
14 | c3 := 2.0 * c1
|
||||||
vlib/v/checker/tests/mul_op_wrong_type_err.vv:15:8: error: infix expr: cannot use `math.complex.Complex` (right expression) as `float literal`
|
vlib/v/checker/tests/mul_op_wrong_type_err.vv:14:8: error: infix expr: cannot use `math.complex.Complex` (right expression) as `float literal`
|
||||||
13 | c2 := c1 * 2.0
|
12 | c2 := c1 * 2.0
|
||||||
14 | println(c2)
|
13 | println(c2)
|
||||||
15 | c3 := 2.0 * c1
|
14 | c3 := 2.0 * c1
|
||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
16 | println(c3)
|
15 | println(c3)
|
||||||
17 | }
|
16 | }
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import math
|
|
||||||
import math.complex as cmplx
|
import math.complex as cmplx
|
||||||
struct Aaa{}
|
struct Aaa{}
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
12
vlib/v/checker/tests/unused_import_err.out
Normal file
12
vlib/v/checker/tests/unused_import_err.out
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
vlib/v/checker/tests/unused_import_err.vv:1:8: warning: module 'te (term)' is imported but never used
|
||||||
|
1 | import term as te
|
||||||
|
| ~~~~
|
||||||
|
2 | import te.ui
|
||||||
|
vlib/v/checker/tests/unused_import_err.vv:2:8: warning: module 'ui (te.ui)' is imported but never used
|
||||||
|
1 | import term as te
|
||||||
|
2 | import te.ui
|
||||||
|
| ~~~~~
|
||||||
|
vlib/v/checker/tests/unused_import_err.vv:2:1: builder error: cannot import module "te.ui" (not found)
|
||||||
|
1 | import term as te
|
||||||
|
2 | import te.ui
|
||||||
|
| ~~~~~~~~~~~~
|
2
vlib/v/checker/tests/unused_import_err.vv
Normal file
2
vlib/v/checker/tests/unused_import_err.vv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import term as te
|
||||||
|
import te.ui
|
|
@ -1,7 +1,6 @@
|
||||||
module js
|
module js
|
||||||
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
|
|
||||||
fn (mut g JsGen) comptime_if(node ast.IfExpr) {
|
fn (mut g JsGen) comptime_if(node ast.IfExpr) {
|
||||||
if !node.is_expr && !node.has_else && node.branches.len == 1 {
|
if !node.is_expr && !node.has_else && node.branches.len == 1 {
|
||||||
|
|
|
@ -5,7 +5,6 @@ module parser
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
|
||||||
import v.token
|
import v.token
|
||||||
|
|
||||||
const supported_comptime_calls = ['html', 'tmpl', 'env', 'embed_file', 'pkgconfig', 'compile_error',
|
const supported_comptime_calls = ['html', 'tmpl', 'env', 'embed_file', 'pkgconfig', 'compile_error',
|
||||||
|
|
|
@ -699,7 +699,7 @@ fn (mut p Parser) check_js_name() string {
|
||||||
fn (mut p Parser) check_name() string {
|
fn (mut p Parser) check_name() string {
|
||||||
pos := p.tok.pos()
|
pos := p.tok.pos()
|
||||||
name := p.tok.lit
|
name := p.tok.lit
|
||||||
if p.peek_tok.kind == .dot && name in p.imports {
|
if p.tok.kind != .name && p.peek_tok.kind == .dot && name in p.imports {
|
||||||
p.register_used_import(name)
|
p.register_used_import(name)
|
||||||
}
|
}
|
||||||
match p.tok.kind {
|
match p.tok.kind {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import net.http
|
import net.http
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
import x.sessions
|
import x.sessions
|
||||||
import x.vweb
|
import x.vweb
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue