Skip to content

value of type 'Future<Database>' can't be assigned to a variable of type 'FutureOr<Database>' #35714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Hixie opened this issue Jan 20, 2019 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@Hixie
Copy link
Contributor

Hixie commented Jan 20, 2019

I don't understand this error. Analyzer says everything is fine.

E/flutter (27033): [ERROR:flutter/shell/common/shell.cc(178)] Dart Error: Unhandled exception:
E/flutter (27033): 'package:cruisemonkey/src/logic/disk_store.dart': error: lib/src/logic/disk_store.dart:16:12: Error: A value of type 'Future<Database>' can't be assigned to a variable of type 'FutureOr<Database>'.
E/flutter (27033):  - 'Future' is from 'dart:async'.
E/flutter (27033):  - 'Database' is from 'package:sqflite/sqflite.dart' ('file:///home/ianh/.pub-cache/hosted/pub.dartlang.org/sqflite-0.13.0+1/lib/sqflite.dart').
E/flutter (27033):  - 'FutureOr' is from 'dart:async'.
E/flutter (27033): Try changing the type of the left hand side, or casting the right hand side to 'FutureOr<Database>'.
E/flutter (27033):     return await openDatabase(
E/flutter (27033):            ^
E/flutter (27033): #0      _AsyncAwaitCompleter.start (dart:async/runtime/libasync_patch.dart:49:6)
E/flutter (27033): #1      DiskDataStore._init (package:cruisemonkey/src/logic/disk_store.dart:15:32)
E/flutter (27033): #2      new DiskDataStore (package:cruisemonkey/src/logic/disk_store.dart:11:33)
E/flutter (27033): #3      main (package:cruisemonkey/main.dart:26:12)
E/flutter (27033): #4      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
E/flutter (27033): #5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

The code in question is:

  static Future<Database> _init() async {
    return await openDatabase( // line 16
      '${await getDatabasesPath()}/config.db',
      version: 2,
      onUpgrade: (Database database, int oldVersion, int newVersion) async {
        final Batch batch = database.batch();
        if (oldVersion < 1) {
          batch.execute('CREATE TABLE credentials (username STRING, password STRING, key STRING, loginTimestamp INTEGER)');
          batch.execute('INSERT INTO credentials DEFAULT VALUES');
        }
        if (oldVersion < 2) {
          batch.execute('CREATE TABLE settings (id INTEGER PRIMARY KEY, value BLOB)');
        }
        await batch.commit(noResult: true);
      },
    );
  }
@Hixie
Copy link
Contributor Author

Hixie commented Jan 20, 2019

I did a flutter clean and tried again and it worked fine. Maybe there's a bug in the compiler regarding how it determines what code needs to be recompiled vs cached?

@mit-mit
Copy link
Member

mit-mit commented Jan 23, 2019

Not sure how to triage this; cc @leafpetersen

@mraleph
Copy link
Member

mraleph commented Jan 23, 2019

@mit-mit this is CFE or VM bug.

Might be actually duplicate of #35715 now that I think about it.

@kevmoo kevmoo added legacy-area-front-end Legacy: Use area-dart-model instead. area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

4 participants