diff --git a/moor_generator/lib/src/analyzer/dart/table_parser.dart b/moor_generator/lib/src/analyzer/dart/table_parser.dart index 274366ef..8e1ab4cd 100644 --- a/moor_generator/lib/src/analyzer/dart/table_parser.dart +++ b/moor_generator/lib/src/analyzer/dart/table_parser.dart @@ -110,13 +110,21 @@ class TableParser { } Future> _parseColumns(ClassElement element) { - final columns = element.allSupertypes + final columnNames = element.allSupertypes .map((t) => t.element) .followedBy([element]) .expand((e) => e.fields) - .where((field) => isColumn(field.type) && field.getter != null); + .where((field) => isColumn(field.type) && field.getter != null) + .map((field) => field.name) + .toSet(); - return Future.wait(columns.map((field) async { + final fields = columnNames.map((name) { + final getter = element.getGetter(name) ?? + element.lookUpInheritedConcreteGetter(name, element.library); + return getter.variable; + }); + + return Future.wait(fields.map((field) async { final resolved = await base.loadElementDeclaration(field.getter); final node = resolved.node as MethodDeclaration; diff --git a/moor_generator/test/analyzer/dart/table_parser_test.dart b/moor_generator/test/analyzer/dart/table_parser_test.dart index bfb99652..876e21bf 100644 --- a/moor_generator/test/analyzer/dart/table_parser_test.dart +++ b/moor_generator/test/analyzer/dart/table_parser_test.dart @@ -53,7 +53,7 @@ void main() { } class Foos extends HasNameTable with IntIdTable { - + TextColumn get name => text().nullable()(); } ''' }); @@ -159,6 +159,7 @@ void main() { test('handles inheritance in column definitions', () async { final table = await parse('Foos'); + expect(table.columns, hasLength(2)); expect(table.columns.map((c) => c.name.name), containsAll(['id', 'name'])); }); }