parser: add an error for `import mod.sub as mod` and `import mod as mod` (#6194)
parent
61df70fdf5
commit
b2e79dbebd
|
@ -1,5 +1,5 @@
|
||||||
// Simple raw HTTP head request
|
// Simple raw HTTP head request
|
||||||
import x.net as net
|
import x.net
|
||||||
import time
|
import time
|
||||||
|
|
||||||
// Make a new connection
|
// Make a new connection
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import math.stats as stats
|
import math.stats
|
||||||
import math
|
import math
|
||||||
|
|
||||||
fn test_freq() {
|
fn test_freq() {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/checker/tests/import_mod_as_mod_err.v:1:16: error: import alias `math as math` is redundant
|
||||||
|
1 | import math as math
|
||||||
|
| ~~~~
|
||||||
|
2 |
|
||||||
|
3 | fn main() {
|
|
@ -0,0 +1,5 @@
|
||||||
|
import math as math
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println(math.e)
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/checker/tests/import_mod_sub_as_sub_err.v:1:25: error: import alias `encoding.utf8 as utf8` is redundant
|
||||||
|
1 | import encoding.utf8 as utf8
|
||||||
|
| ~~~~
|
||||||
|
2 |
|
||||||
|
3 | fn main() {
|
|
@ -0,0 +1,5 @@
|
||||||
|
import encoding.utf8 as utf8
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println(utf8.validate_str('añçá'))
|
||||||
|
}
|
|
@ -1495,6 +1495,9 @@ fn (mut p Parser) import_stmt() ast.Import {
|
||||||
if p.tok.kind == .key_as {
|
if p.tok.kind == .key_as {
|
||||||
p.next()
|
p.next()
|
||||||
mod_alias = p.check_name()
|
mod_alias = p.check_name()
|
||||||
|
if mod_alias == mod_name.split('.').last() {
|
||||||
|
p.error_with_pos('import alias `$mod_name as $mod_alias` is redundant', p.prev_tok.position())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
node := ast.Import{
|
node := ast.Import{
|
||||||
pos: pos
|
pos: pos
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import x.net as net
|
import x.net
|
||||||
import time
|
import time
|
||||||
|
|
||||||
fn echo_server(_c net.UdpConn) {
|
fn echo_server(_c net.UdpConn) {
|
||||||
|
|
Loading…
Reference in New Issue