Skip to content

Unsupported operation: Undetermined Nullability #48752

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

Closed
hamishjohnson opened this issue Apr 6, 2022 · 8 comments
Closed

Unsupported operation: Undetermined Nullability #48752

hamishjohnson opened this issue Apr 6, 2022 · 8 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler

Comments

@hamishjohnson
Copy link

hamishjohnson commented Apr 6, 2022

Describe the bug
This code crashes when you build for web, but not for mobile.

I'm able to reproduce with the Riverpod package, but I don't know enough about the problem to reproduce without riverpod. I opened an issue there but maintainer Remi Rousselet believes it's a dart issue, so I'm reposting here.

To Reproduce

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

void main() {
  runApp(const ProviderScope(child: MyApp()));
}

class MyApp extends ConsumerWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final value = ref.watch(stringProvider);

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(body: Text(value.value ?? '')),
    );
  }
}

const condition = false;

final stringProvider = FutureProvider<String>((ref) {
  if (condition) return 'child'; // <==== This line is what causes the bug

  return future();
});

Future<String> future() async {
  await Future.delayed(const Duration(seconds: 1));

  return 'done';
}

Expected behavior
Run on mobile, works fine. Run on web, compile crashes.

When adding 'async' to the provided create function, it works fine.

Error
Launching lib[/main.dart]() on Chrome in debug mode...
lib/main.dart:1
Unhandled exception:
Unsupported operation: Undetermined Nullability
#0      ProgramCompiler._emitFutureOrType (package:dev_compiler[/src/kernel/compiler.dart:3057:7]())
#1      ProgramCompiler.visitFutureOrType (package:dev_compiler[/src/kernel/compiler.dart:2948:11]())
#2      FutureOrType.accept (package:kernel[/ast.dart:11519:42]())
#3      ProgramCompiler._emitType (package:dev_compiler[/src/kernel/compiler.dart:2847:54]())
#4      ProgramCompiler.visitFunctionType (package:dev_compiler[/src/kernel/compiler.dart:3138:22]())
#5      ProgramCompiler._emitFunctionTagged (package:dev_compiler[/src/kernel/compiler.dart:2803:19]())
#6      ProgramCompiler.visitFunctionExpression (package:dev_compiler[/src/kernel/compiler.dart:6186:12]())
#7      FunctionExpression.accept (package:kernel[/ast.dart:8292:44]())
#8      ProgramCompiler._visitExpression (package:dev_compiler[/src/kernel/compiler.dart:3870:20]())
#9      ProgramCompiler._emitArgumentList (package:dev_compiler[/src/kernel/compiler.dart:5614:11]())

#10     ProgramCompiler.visitConstructorInvocation (package:dev_compiler[/src/kernel/compiler.dart:5761:9]())
#11     ConstructorInvocation.accept (package:kernel[/ast.dart:6392:44]())
#12     ProgramCompiler._visitExpression (package:dev_compiler[/src/kernel/compiler.dart:3870:20]())
#13     ProgramCompiler._visitInitializer (package:dev_compiler[/src/kernel/compiler.dart:1786:11]())
#14     ProgramCompiler._emitStaticFieldInitializer.<anonymous closure> (package:dev_compiler[/src/kernel/compiler.dart:2366:23]())
#15     ProgramCompiler._withLetScope (package:dev_compiler[/src/kernel/compiler.dart:2376:25]())
#16     ProgramCompiler._emitStaticFieldInitializer (package:dev_compiler[/src/kernel/compiler.dart:2364:40]())
#17     ProgramCompiler._emitLazyFields (package:dev_compiler[/src/kernel/compiler.dart:2339:43]())
#18     ProgramCompiler._emitTopLevelFields (package:dev_compiler[/src/kernel/compiler.dart:2323:21]())
#19     ProgramCompiler._emitLibrary (package:dev_compiler[/src/kernel/compiler.dart:573:7]())
#20     List.forEach (dart:core-patch[/growable_array.dart:433:8]())
#21     ProgramCompiler.emitModule (package:dev_compiler[/src/kernel/compiler.dart:431:15]())
#22     JavaScriptBundler.compile (package:frontend_server[/src/javascript_bundle.dart:152:33]())
<asynchronous suspension>
#23     FrontendCompiler.writeJavascriptBundle (package:frontend_server[/frontend_server.dart:665:32]())

<asynchronous suspension>
#24     FrontendCompiler.compile (package:frontend_server[/frontend_server.dart:573:9]())
<asynchronous suspension>
#25     listenAndCompile.<anonymous closure> (package:frontend_server[/frontend_server.dart:1154:11]())
<asynchronous suspension>

the Dart compiler exited unexpectedly.
Exited (sigterm)
Failed to compile application.

Edit:

I forgot to add that I was able to fix the issue in the meantime by wrapping the value in a future, like so

Replace
if (condition) return 'child'; // <==== This line is what causes the bug

With
if (condition) return Future.value('child');

In case that helps anybody

@caleb654
Copy link

caleb654 commented Apr 6, 2022

Also using Riverpod and getting this issue. I am able to build a release build, but in debug, it crashes every time.

@caleb654
Copy link

caleb654 commented Apr 6, 2022

@hamishjohnson How did you figure out which line was causing the issue? I'm not able to get any details about that in the stack trace?

@hamishjohnson
Copy link
Author

hamishjohnson commented Apr 6, 2022

I was just trial and errored it. By the way, I updated the post with a fix (wrapping in a Future) in case that helps you. Check if you have any FutureProviders that aren't returning a Future. If not, it might be an unrelated issue

But the bug still exists

@devoncarew
Copy link
Member

Highlighting the stack trace from above:

Launching lib[/main.dart]() on Chrome in debug mode...
lib/main.dart:1
Unhandled exception:
Unsupported operation: Undetermined Nullability
#0      ProgramCompiler._emitFutureOrType (package:dev_compiler[/src/kernel/compiler.dart:3057:7]())
#1      ProgramCompiler.visitFutureOrType (package:dev_compiler[/src/kernel/compiler.dart:2948:11]())
#2      FutureOrType.accept (package:kernel[/ast.dart:11519:42]())
#3      ProgramCompiler._emitType (package:dev_compiler[/src/kernel/compiler.dart:2847:54]())
#4      ProgramCompiler.visitFunctionType (package:dev_compiler[/src/kernel/compiler.dart:3138:22]())
#5      ProgramCompiler._emitFunctionTagged (package:dev_compiler[/src/kernel/compiler.dart:2803:19]())
#6      ProgramCompiler.visitFunctionExpression (package:dev_compiler[/src/kernel/compiler.dart:6186:12]())
#7      FunctionExpression.accept (package:kernel[/ast.dart:8292:44]())
#8      ProgramCompiler._visitExpression (package:dev_compiler[/src/kernel/compiler.dart:3870:20]())
#9      ProgramCompiler._emitArgumentList (package:dev_compiler[/src/kernel/compiler.dart:5614:11]())

#10     ProgramCompiler.visitConstructorInvocation (package:dev_compiler[/src/kernel/compiler.dart:5761:9]())
#11     ConstructorInvocation.accept (package:kernel[/ast.dart:6392:44]())
#12     ProgramCompiler._visitExpression (package:dev_compiler[/src/kernel/compiler.dart:3870:20]())
#13     ProgramCompiler._visitInitializer (package:dev_compiler[/src/kernel/compiler.dart:1786:11]())
#14     ProgramCompiler._emitStaticFieldInitializer.<anonymous closure> (package:dev_compiler[/src/kernel/compiler.dart:2366:23]())
#15     ProgramCompiler._withLetScope (package:dev_compiler[/src/kernel/compiler.dart:2376:25]())
#16     ProgramCompiler._emitStaticFieldInitializer (package:dev_compiler[/src/kernel/compiler.dart:2364:40]())
#17     ProgramCompiler._emitLazyFields (package:dev_compiler[/src/kernel/compiler.dart:2339:43]())
#18     ProgramCompiler._emitTopLevelFields (package:dev_compiler[/src/kernel/compiler.dart:2323:21]())
#19     ProgramCompiler._emitLibrary (package:dev_compiler[/src/kernel/compiler.dart:573:7]())
#20     List.forEach (dart:core-patch[/growable_array.dart:433:8]())
#21     ProgramCompiler.emitModule (package:dev_compiler[/src/kernel/compiler.dart:431:15]())
#22     JavaScriptBundler.compile (package:frontend_server[/src/javascript_bundle.dart:152:33]())
<asynchronous suspension>
#23     FrontendCompiler.writeJavascriptBundle (package:frontend_server[/frontend_server.dart:665:32]())

<asynchronous suspension>
#24     FrontendCompiler.compile (package:frontend_server[/frontend_server.dart:573:9]())
<asynchronous suspension>
#25     listenAndCompile.<anonymous closure> (package:frontend_server[/frontend_server.dart:1154:11]())
<asynchronous suspension>

the Dart compiler exited unexpectedly.
Exited (sigterm)
Failed to compile application.

@devoncarew devoncarew added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Apr 6, 2022
@gmpassos
Copy link
Contributor

gmpassos commented Apr 6, 2022

Maybe related to:
#48631

FYI: @chloestefantsova

@nshahan
Copy link
Contributor

nshahan commented Apr 6, 2022

@chloestefantsova recently fixed two similar issues. One has already rolled into flutter main, but the second hasn't yet. The second fix was for an issue reported by another user with a RiverPod dependency #48631 (comment). I suspect this will be fixed by one of those changes and I'd like to verify if the issue is still present at flutter master after the second fix has rolled in.

@chloestefantsova
Copy link
Contributor

I think so too, that my recent fix should resolve this issue. I try to locally verify that.

@chloestefantsova
Copy link
Contributor

Ok, @whesse checked the fix that's already in the Dart SDK, and it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler
Projects
None yet
Development

No branches or pull requests

7 participants