From 2002d202496fedddcc31eab22acce7aeab013f43 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 17 Feb 2021 01:37:05 +0200 Subject: [PATCH] io: remove unused Zzz_CoerceInterfaceTableGeneration struct; add test for `x := Enum{}` --- vlib/io/readerwriter.v | 18 +----------------- vlib/v/gen/c/cgen.v | 6 ++---- vlib/v/tests/enum_test.v | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/vlib/io/readerwriter.v b/vlib/io/readerwriter.v index 8c0dfa5fb1..b285f71111 100644 --- a/vlib/io/readerwriter.v +++ b/vlib/io/readerwriter.v @@ -4,7 +4,7 @@ module io pub interface ReaderWriter { // from Reader read(mut buf []byte) ?int - // from Writer + // from Writer write(buf []byte) ?int } @@ -31,19 +31,3 @@ pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl { w: w } } - -struct Zzz_CoerceInterfaceTableGeneration { -} - -fn (_ Zzz_CoerceInterfaceTableGeneration) write(buf []byte) ?int { - return none -} - -fn (_ Zzz_CoerceInterfaceTableGeneration) read(mut buf []byte) ?int { - return none -} - -fn zzz_reader_writer_coerce_compiler() { - x := Zzz_CoerceInterfaceTableGeneration{} - _ := make_readerwriter(x, x) -} diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 55d06b37fc..4b3541151a 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5037,10 +5037,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) { g.indent-- } - if g.pref.ccompiler == 'msvc' { - if !initialized { - g.write('\n#ifndef __cplusplus\n0\n#endif\n') - } + if !initialized { + g.write('\n#ifndef __cplusplus\n0\n#endif\n') } g.write('}') diff --git a/vlib/v/tests/enum_test.v b/vlib/v/tests/enum_test.v index 7e8a3be20e..1c5bf874b9 100644 --- a/vlib/v/tests/enum_test.v +++ b/vlib/v/tests/enum_test.v @@ -34,7 +34,7 @@ fn test_enum() { fn test_in() { color := Color.red - num := 3 // used to be an expr bug before `in` + num := 3 // used to be an expr bug before `in` assert color in [.red, .green] assert num == 3 println(color) @@ -118,3 +118,18 @@ fn test_typed_enum() { } } */ + +enum FileType { + unknown + wiki + file + image + html +} + +fn test_enum_instance() { + mut filetype := FileType{} + eprintln(filetype) + s := 'x $filetype z' + assert s == 'x unknown z' +}