From f14425ec1829041deae5bcc4c9649126ea292f75 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 23 Oct 2019 17:02:39 +0300 Subject: [PATCH] do not allow one letter struct names --- examples/tetris/tetris.v | 8 +++----- vlib/builtin/option.v | 1 + vlib/compiler/parser.v | 13 ++++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index 5ede31d8e6..e4fa529669 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -324,23 +324,21 @@ fn (g &Game) draw_field() { } fn (g mut Game) draw_ui() { - if g.font_loaded {WinHeight / 2 + 2 * TextSize + if g.font_loaded { g.ft.draw_text(1, 2, 'score: ' + g.score.str(), text_cfg) if g.state == .gameover { g.gg.draw_rect(0, WinHeight / 2 - TextSize, WinWidth, - 5 * TextSize, UIColor) + 5 * TextSize, UIColor) g.ft.draw_text(1, WinHeight / 2 + 0 * TextSize, 'Game Over', text_cfg) g.ft.draw_text(1, WinHeight / 2 + 2 * TextSize, 'SPACE to restart', text_cfg) } else if g.state == .paused { g.gg.draw_rect(0, WinHeight / 2 - TextSize, WinWidth, - 5 * TextSize, UIColor) + 5 * TextSize, UIColor) g.ft.draw_text(1, WinHeight / 2 + 0 * TextSize, 'Game Paused', text_cfg) g.ft.draw_text(1, WinHeight / 2 + 2 * TextSize, 'SPACE to resume', text_cfg) } } - g.gg.draw_rect(0, BlockSize, WinWidth, LimitThickness, UIColor) - } fn (g mut Game) draw_scene() { diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index f504b6161f..2007a29623 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -23,6 +23,7 @@ fn opt_ok(data voidptr, size int) Option { return res } +// used internally when returning `none` fn opt_none() Option { return Option{ is_none: true } } diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index d7297c9163..3a1e077575 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -684,6 +684,9 @@ fn (p mut Parser) struct_decl() { cat = .c_typedef } } + if name.len == 1 && !p.pref.building_v && !p.pref.is_repl { + p.warn('struct names must have more than one character') + } if !is_c && !good_type_name(name) { p.error('bad struct name, e.g. use `HttpRequest` instead of `HTTPRequest`') } @@ -693,11 +696,11 @@ fn (p mut Parser) struct_decl() { } mut typ := p.table.find_type(name) if p.pass == .decl && p.table.known_type_fast(typ) { - if name in reserved_type_param_names { - p.error('name `$name` is reserved for type parameters') - } else { - p.error('type `$name` redeclared') - } + //if name in reserved_type_param_names { + //p.error('name `$name` is reserved for type parameters') + //} else { + p.error('type `$name` redeclared') + //} } if is_objc { // Forward declaration of an Objective-C interface with `@class` :)