Skip to content

Mistaken nullability warning when compiling executable #48090

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
renatoathaydes opened this issue Jan 6, 2022 · 4 comments
Closed

Mistaken nullability warning when compiling executable #48090

renatoathaydes opened this issue Jan 6, 2022 · 4 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@renatoathaydes
Copy link

May be related to #46264

I have a package, actors, which is now emitting this warning when a binary depending on it is compiled:

▶ dart compile exe bin/dartle.dart
Info: Compiling with sound null safety
../../../.pub-cache/hosted/pub.dartlang.org/actors-0.8.1/lib/src/isolate/isolate_actor.dart:35:39: Warning: Operand of null-aware operation '??' has type 'String' which excludes null.
  final isolateName = Isolate.current.debugName ?? '';
                                      ^
Generated: /Users/renato/programming/projects/dartle/bin/dartle.exe

This is very weird because I am using Dart 2.15.1 and the actors package uses the environment config sdk: '>=2.15.0 <3.0.0' (same as the package I am currently compiling), which I updated to try to get rid of this warning (I thought the nullability of this property might have changed between Dart 2.14 and 2.15 - but that's not the case).

Isolate.current.debugName is certainly nullable, and it appears to have been nullable at least since Dart 2.9.0: https://api.dart.dev/stable/2.9.0/dart-isolate/Isolate/debugName.html (it wasn't nullable up until 2.8.0).

What could be the issue?

@renatoathaydes
Copy link
Author

Maybe this helps: my tests for another project started failing just recently because of this.. the test monitors stderr and the output has changed:

https://github.com/renatoathaydes/dartle/runs/4731870282?check_suite_focus=true

Expected: []
	  Actual: [
	            '../../../../../../.pub-cache/hosted/pub.dartlang.org/actors-0.8.0/lib/src/isolate/isolate_actor.dart:35:39: Warning: Operand of null-aware operation \'??\' has type \'String\' which excludes null.',
	            '  final isolateName = Isolate.current.debugName ?? \'\';',
	            '                                      ^'
	          ]

So, this is looking like a regression in Dart 2.15.

@lrhn lrhn added the legacy-area-front-end Legacy: Use area-dart-model instead. label Jan 6, 2022
@johnniwinther
Copy link
Member

This is caused by a discrepancy between the declaration of Isolate.debugName which has type String? and the patch implementation which has type String. The front-end uses the implementation types.

I'll update the patch implementation to match the declaration.

@johnniwinther johnniwinther self-assigned this Jan 7, 2022
@renatoathaydes
Copy link
Author

Thanks @johnniwinther . This is breaking my build, so can you tell me when/which is the next release that will include this coming up?

@johnniwinther
Copy link
Member

It might take while before it is available in stable release. Until then you can use one of these work-arounds:

Indirection through local with type dynamic:

String _generateName() {
   final dynamic isolateNameWorkaround = Isolate.current.debugName;
   final String isolateName = isolateNameWorkaround ?? '';

Access through a helper:

String? get _isolateNameWorkaround => Isolate.current.debugName;
String _generateName() {
  final isolateName = _isolateNameWorkaround ?? '';

renatoathaydes added a commit to renatoathaydes/actors that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

3 participants