checker: do not allow module aliases started with '_' (underscore) (#9588)

pull/9648/head
Caian R. Ertl 2021-04-09 07:14:27 -03:00 committed by GitHub
parent 84fa1ae444
commit ddb2e72301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View File

@ -3977,6 +3977,7 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
}
fn (mut c Checker) import_stmt(imp ast.Import) {
c.check_valid_snake_case(imp.alias, 'module alias', imp.pos)
for sym in imp.syms {
name := '${imp.mod}.$sym.name'
if sym.name[0].is_capital() {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/modules/module_alias_started_with_underscore/main.v:3:1: error: module alias `_` cannot start with `_`
1 | module main
2 |
3 | import underscore as _
| ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | fn main() {

View File

@ -0,0 +1,7 @@
module main
import underscore as _
fn main() {
_.foo()
}

View File

@ -0,0 +1,5 @@
module underscore
pub fn foo() {
println('bar')
}