From ba40dd4bbacd5d12d38706a0ab59d9a148aa8eca Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Sat, 31 Jan 2026 21:32:46 -0500 Subject: [PATCH] fix single char types --- .../012_check_if_list_contains_a_value.go | 20 ------------------- struct.v | 6 +++++- tests/single_char_type/single_char_type.go | 17 ++++++++++++++++ tests/single_char_type/single_char_type.vv | 14 +++++++++++++ 4 files changed, 36 insertions(+), 21 deletions(-) delete mode 100644 idioms/012_check_if_list_contains_a_value/012_check_if_list_contains_a_value.go create mode 100644 tests/single_char_type/single_char_type.go create mode 100644 tests/single_char_type/single_char_type.vv diff --git a/idioms/012_check_if_list_contains_a_value/012_check_if_list_contains_a_value.go b/idioms/012_check_if_list_contains_a_value/012_check_if_list_contains_a_value.go deleted file mode 100644 index 00e0f61..0000000 --- a/idioms/012_check_if_list_contains_a_value/012_check_if_list_contains_a_value.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import "fmt" - -func Contains(list []T, x T) bool { - for _, item := range list { - if item == x { - return true - } - } - return false -} - -type T string - -func main() { - list := []T{"a", "b", "c"} - fmt.Println(Contains(list, "b")) - fmt.Println(Contains(list, "z")) -} \ No newline at end of file diff --git a/struct.v b/struct.v index ba84852..20cec3e 100644 --- a/struct.v +++ b/struct.v @@ -62,7 +62,11 @@ fn (mut app App) type_decl(spec TypeSpec) { // Remember the type name for the upcoming const (enum) handler if it's an enum name := spec.name.name // V requires type aliases to start with a capital letter - v_name := name.capitalize() + mut v_name := name.capitalize() + // If only 1 char in name, double it + if v_name.len == 1 { + v_name += v_name + } // Store alias info app.struct_or_alias << name app.struct_or_alias << v_name diff --git a/tests/single_char_type/single_char_type.go b/tests/single_char_type/single_char_type.go new file mode 100644 index 0000000..587c68c --- /dev/null +++ b/tests/single_char_type/single_char_type.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "math/rand" +) + +type T string + +func pickT(x []T) T { + return x[rand.Intn(len(x))] +} + +func main() { + var list = []T{"bleen", "fuligin", "garrow", "grue", "hooloovoo"} + fmt.Println(pickT(list)) +} \ No newline at end of file diff --git a/tests/single_char_type/single_char_type.vv b/tests/single_char_type/single_char_type.vv new file mode 100644 index 0000000..f89a181 --- /dev/null +++ b/tests/single_char_type/single_char_type.vv @@ -0,0 +1,14 @@ +module main + +import rand + +type TT = string + +fn pick_t(x []TT) TT { + return x[rand.intn(x.len)] +} + +fn main() { + mut list := ['bleen', 'fuligin', 'garrow', 'grue', 'hooloovoo'] + println(pick_t(list)) +}