From 8bce5cb810929652ef548268468c46f48c01d5e1 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 4 Aug 2019 09:16:44 +0200 Subject: [PATCH] force snake_case in struct fields --- compiler/parser.v | 3 +++ vlib/builtin/int_test.v | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 vlib/builtin/int_test.v diff --git a/compiler/parser.v b/compiler/parser.v index c5e686ffb6..bc62eb2cbc 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -592,6 +592,9 @@ fn (p mut Parser) struct_decl() { if field_name in names { p.error('duplicate field `$field_name`') } + if p.mod != 'os' && contains_capital(field_name) { + p.error('struct fields cannot contain uppercase letters, use snake_case instead') + } names << field_name // We are in an interface? // `run() string` => run is a method, not a struct field diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v new file mode 100644 index 0000000000..138871618b --- /dev/null +++ b/vlib/builtin/int_test.v @@ -0,0 +1,7 @@ +const ( + a = 3 +) + +fn test_const() { + assert a == 3 +}