diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 84ee4087c8..1680435cb3 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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() { diff --git a/vlib/v/checker/tests/modules/module_alias_started_with_underscore.out b/vlib/v/checker/tests/modules/module_alias_started_with_underscore.out new file mode 100644 index 0000000000..a0cc315c1b --- /dev/null +++ b/vlib/v/checker/tests/modules/module_alias_started_with_underscore.out @@ -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() { diff --git a/vlib/v/checker/tests/modules/module_alias_started_with_underscore/main.v b/vlib/v/checker/tests/modules/module_alias_started_with_underscore/main.v new file mode 100644 index 0000000000..39f80a1cfb --- /dev/null +++ b/vlib/v/checker/tests/modules/module_alias_started_with_underscore/main.v @@ -0,0 +1,7 @@ +module main + +import underscore as _ + +fn main() { + _.foo() +} diff --git a/vlib/v/checker/tests/modules/module_alias_started_with_underscore/underscore.v b/vlib/v/checker/tests/modules/module_alias_started_with_underscore/underscore.v new file mode 100644 index 0000000000..ec83c1ca7a --- /dev/null +++ b/vlib/v/checker/tests/modules/module_alias_started_with_underscore/underscore.v @@ -0,0 +1,5 @@ +module underscore + +pub fn foo() { + println('bar') +}