Skip to content

Debugger showing Mixin's static field always as null #51027

@MajedDH

Description

@MajedDH

Dart version: Dart SDK version: 2.18.7 (stable) (Unknown timestamp) on "linux_x64" working on Ubuntu 22.04
Let's consider the following main.dart file:

import 'dart:async';

class A with B {}

mixin B {
  static DateTime? lastTick;
  static Timer? checkActiveTimer;

  void startTimer() {
    checkActiveTimer = Timer.periodic(Duration(seconds: 1), (timer) {
      lastTick = DateTime.now();
      print(lastTick); //break point here
    });
  }

   bool lastActiveIsNull() {
    return lastActive == null;
  }
}

Future<void> main(List<String> arguments) async {
  var a = A();
  a.startTimer();
}
  1. I've ran this file using the command /usr/lib/dart/bin/dart --enable-vm-service:34213 main.dart and got into the devtools to debug it. When the execution pauses at the break point. the lastTick member is evaluated inside the debugger as null. It's being printed and used inside the code correctly but the debugger is evaluating it wrongly as null.
    If I asked the debugger to evaluate B.lastTick it'll view it's value correctly, or If I used lastActiveIsNull() it'll return false so only calling the member directly in the watches will show null including for example print(lastTick), evaluating it will print null but calling it actually from the code will print it. shouldn't the two of them evaluate and work as the same value?

  2. If I tried to evaluate this or call any kind of member instance method from inside the function inside the timer it'll throw out optimized out which is ok. I understand why. But if we call instance method like lastActiveIsNull() it'll throw NoSuchMethodError: Class 'String' has no instance method 'lastActiveIsNull'. which is not as clear. shouldn't it show optimized out or similiar errors rather than the String related error?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions