Skip to content
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

Expression evaluation on extension getters for nullable types throw exception #57040

Open
FMorschel opened this issue Nov 6, 2024 · 1 comment
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-service The VM Service Protocol, both the specification and its implementation

Comments

@FMorschel
Copy link
Contributor

Repro

extension on String? {
  bool get isNullOrEmpty {
    var str = this;
    return str == null || str.isEmpty;
  }
}

void main() {
  String? str;
  print(str.isNullOrEmpty);
}

Place a breakpoint on print and evaluate str.isNullOrEmpty you get:

Unhandled exception:
NoSuchMethodError: The getter 'isNullOrEmpty' was called on null.
Receiver: null
Tried calling: isNullOrEmpty
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1      Eval ()
#2      main (package:bug/a.dart:10:13)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

CC: @bkonyi

@dart-github-bot
Copy link
Collaborator

Summary: The issue is that evaluating an extension getter on a nullable type that is null throws a NoSuchMethodError instead of returning the expected value. This occurs when using a breakpoint in the debugger to evaluate the expression.

@dart-github-bot dart-github-bot added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 6, 2024
@bkonyi bkonyi added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team vm-service The VM Service Protocol, both the specification and its implementation and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Nov 6, 2024
@devoncarew devoncarew removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Nov 6, 2024
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. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-service The VM Service Protocol, both the specification and its implementation
Projects
None yet
Development

No branches or pull requests

5 participants