Skip to content

Commit

Permalink
Fix attached index not resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Dec 4, 2023
1 parent 09d450e commit 27b459d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
11 changes: 9 additions & 2 deletions drift/example/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions drift_dev/lib/src/analysis/driver/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ class DriftAnalysisDriver {
assert(state.discovery != null || state.cachedDiscovery != null);
assert(id.libraryUri == state.ownUri);

if (!state.elementIsAnalyzed(id)) {
if (state.elementIsAnalyzed(id)) {
return state.analysis[id]?.result;
} else {
final resolver = DriftResolver(this);

try {
Expand All @@ -241,10 +243,10 @@ class DriftAnalysisDriver {

if (_isTesting) rethrow;
}

return null;
}
}

return null;
}

/// Resolves elements in a file under the given [uri] by doing all the
Expand Down
28 changes: 28 additions & 0 deletions drift_dev/test/writer/table_writer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ class Tags extends Table {
}, result.dartOutputs, result.writer);
});

test('generates index attached to table in same file', () async {
// Regression test for https://github.com/simolus3/drift/discussions/2766
final result = await emulateDriftBuild(
inputs: {
'a|lib/a.dart': '''
import 'package:drift/drift.dart';
@TableIndex(name: 'tag_id', columns: {#id})
class Tags extends Table {
IntColumn get id => integer().autoIncrement()();
}
@DriftDatabase(tables: [Tags])
class MyDatabase {}
''',
},
);

checkOutputs({
'a|lib/a.drift.dart': decodedMatches(allOf(
contains(
"Index tagId = Index('tag_id', 'CREATE INDEX tag_id ON tags (id)')",
),
contains('allSchemaEntities => [tags, tagId]'),
)),
}, result.dartOutputs, result.writer);
});

test('generates index attached to table in modular build', () async {
final result = await emulateDriftBuild(
inputs: {
Expand Down

0 comments on commit 27b459d

Please sign in to comment.