sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Weird super parameters evaluation + assert breakpoints not triggering

Open FMorschel opened this issue 5 months ago • 1 comments

Repro:

class One {
  One(this.numbers)
    : assert(numbers.map((e) => e).isNotEmpty, ''), //B5 (will explain below)
      assert(numbers.isNotEmpty, ''); //B6 (will explain below)

  List<int> numbers;
}

class Two extends One {
  Two(super.numbers) // B1
    : assert(numbers.map((e) => e).isNotEmpty, ''), //B2
      assert(numbers.isNotEmpty, ''); //B3
}

class Three extends One {
  Three(super.numbers) : assert(numbers.map((e) => e).isNotEmpty, ''); //B4
}

void main() {
  var two = Two([1, 2]);
  print(two.numbers);
  var three = Three([1, 2]);
  print(three.numbers);
  var one = One([1, 2]);
  print(one.numbers);
}
  1. For some reason, the List.map never triggers a breakpoint.
  2. The numbers expression is null:

Image

But when on One (B5 and B6), evaluation does work as intended, but B5 doesn't trigger. The only way I found to get there was to place a breakpoint on the constructor line and press F10 (VS Code next).


This case will trigger the breakpoint, although I'm not sure what is different here still:

class Data {
  Data(this.number);
  num number;
  List<int> get list => switch (number) {
    int v => [v],
    double() => [number.toInt()],
  };
}

class Foo<T> {
  Foo(this.value);
  T value;
}

class Bar extends Foo<Data> {
  Bar(super.value, int other)
    : assert(value.list.map((i) => i).contains(other)); //Break
}

void main() {
  var data = Data(42);
  var bar = Bar(data, 42);
  print(bar.value.list);
}

FMorschel avatar Jun 12 '25 19:06 FMorschel

As a note, this all happened while trying to repro a crash I saw on evaluation on stable. I can't seem to repro it on master, so I'll try again on stable.

Edit: I've managed to repro only with the same project I was working on. I've opened https://github.com/dart-lang/sdk/issues/60913.

FMorschel avatar Jun 12 '25 20:06 FMorschel

FYI @biggs0125

FMorschel avatar Oct 09 '25 15:10 FMorschel

@bkonyi We should look at this with https://github.com/dart-lang/sdk/issues/60913

biggs0125 avatar Oct 09 '25 18:10 biggs0125