Skip to content

Commit 9ce1c16

Browse files
committed
Give variable firstOpen a type to prepare for Dart language bugfix.
This change prepares for the Dart language to roll out the fix for dart-lang/language#1785. This bug prevents implicitly typed condition variables from participating in type promotion in some circumstances (see the bug for more details). There's one variable in this package that's affected - the `firstOpen` variable. Since the bug only occurs when the condition variable is implicitly typed, we can ensure a smooth rollout by giving `firstOpen` an explicit `bool` type. Once the fix has fully rolled out, and the package depends on a version of Dart that includes the bug fix, we will be able to remove this explicit type once again.
1 parent e2cdb37 commit 9ce1c16

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sqflite_common/lib/src/factory_mixin.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ mixin SqfliteDatabaseFactoryMixin
9898

9999
var databaseOpenHelper = getExistingDatabaseOpenHelper(path);
100100

101-
final firstOpen = databaseOpenHelper == null;
101+
// TODO(https://github.com/dart-lang/sdk/issues/47065): remove this
102+
// explicit `bool` type when no longer needed to work around
103+
// https://github.com/dart-lang/language/issues/1785
104+
final bool firstOpen = databaseOpenHelper == null;
102105
if (firstOpen) {
103106
databaseOpenHelper = SqfliteDatabaseOpenHelper(this, path, options);
104107
setDatabaseOpenHelper(databaseOpenHelper);
105108
}
106109
try {
107-
return await databaseOpenHelper!.openDatabase();
110+
return await databaseOpenHelper.openDatabase();
108111
} catch (e) {
109112
// If first open fail remove the reference
110113
if (firstOpen) {

0 commit comments

Comments
 (0)