From c7bea03ce35af0277492a30cda8705f93d2f8761 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 9 Dec 2020 20:08:51 +0200 Subject: [PATCH] ci: fix msvc _name_table [0]{} generation --- .github/workflows/ci.yml | 2 +- vlib/v/gen/cgen.v | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2eaf3b3968..03a907b42e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -395,7 +395,7 @@ jobs: run: | echo %VFLAGS% echo $VFLAGS - .\make.bat + .\make.bat -msvc .\v.exe -cflags /WX self - name: Install dependencies run: | diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 348b752575..72f3c05900 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -5627,13 +5627,18 @@ fn (mut g Gen) interface_table() string { // as well as case functions from the struct to the interface mut methods_struct := strings.new_builder(100) mut staticprefix := 'static' + iname_table_length := inter_info.types.len if g.pref.ccompiler == 'msvc' { - // msvc can not process `static struct x[0] = {};` - // for now just skip adding `static`. - // TODO: generate a non empty _name_table in this case, a dummy element... staticprefix = '' + if iname_table_length == 0 { + // msvc can not process `static struct x[0] = {};` + methods_struct.writeln('$staticprefix $methods_struct_name ${interface_name}_name_table[1];') + }else{ + methods_struct.writeln('$staticprefix $methods_struct_name ${interface_name}_name_table[$iname_table_length] = {') + } + } else { + methods_struct.writeln('$staticprefix $methods_struct_name ${interface_name}_name_table[$iname_table_length] = {') } - methods_struct.writeln('$staticprefix $methods_struct_name ${interface_name}_name_table[$inter_info.types.len] = {') mut cast_functions := strings.new_builder(100) cast_functions.write('// Casting functions for interface "$interface_name"') mut methods_wrapper := strings.new_builder(100) @@ -5719,7 +5724,11 @@ _Interface* I_${cctype}_to_Interface_${interface_name}_ptr($cctype* x) { sb.writeln('int $interface_index_name = $iin_idx;') } sb.writeln('// ^^^ number of types for interface $interface_name: ${current_iinidx - iinidx_minimum_base}') - methods_struct.writeln('};') + if g.pref.ccompiler == 'msvc' && iname_table_length == 0 { + methods_struct.writeln('') + }else { + methods_struct.writeln('};') + } // add line return after interface index declarations sb.writeln('') sb.writeln(methods_wrapper.str())