From 98cd013908beba7fe30a7db3ff10084afe82313a Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Wed, 29 Apr 2020 21:08:39 +1000 Subject: [PATCH] cgen: fix interface struct sorting --- vlib/v/gen/cgen.v | 14 +++++++++----- vlib/v/tests/interface_test.v | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 69be8e8317..46ecb523f4 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -599,11 +599,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { } ast.Import {} ast.InterfaceDecl { - g.definitions.writeln('//interface') - g.definitions.writeln('typedef struct {') - g.definitions.writeln('\tvoid* _object;') - g.definitions.writeln('\tint _interface_idx;') - g.definitions.writeln('} $it.name;') + // definitions are sorted and added in write_types } ast.Module { g.is_builtin_mod = it.name == 'builtin' @@ -2271,6 +2267,13 @@ int typ; g.definitions.writeln('typedef $fixed $styp [$len];') // } } + table.Interface { + g.definitions.writeln('//interface') + g.definitions.writeln('typedef struct {') + g.definitions.writeln('\tvoid* _object;') + g.definitions.writeln('\tint _interface_idx;') + g.definitions.writeln('} $typ.name;') + } else {} } } @@ -2287,6 +2290,7 @@ fn (g Gen) sort_structs(typesa []table.TypeSymbol) []table.TypeSymbol { // loop over types for t in typesa { if t.kind == .interface_ { + dep_graph.add(t.name, []) continue } // create list of deps diff --git a/vlib/v/tests/interface_test.v b/vlib/v/tests/interface_test.v index 6af3426508..087d211a79 100644 --- a/vlib/v/tests/interface_test.v +++ b/vlib/v/tests/interface_test.v @@ -81,7 +81,7 @@ interface Speaker2 { struct Foo { - //speaker Speaker - //speakers []Speaker + speaker Speaker + speakers []Speaker }