Skip to content

[vm] Default values of noSuchMethod forwarder are missed in case of mixin application #53656

Closed
@sgrekhov

Description

@sgrekhov

According to Dart specification "10.2.2 The Method noSuchMethod"

A noSuchMethod forwarder is a concrete member of C with the signature
taken from the interface of C, and with the same default value for each optional
parameter

But in case of mixin application on VM default values of optional parameters are missed. Proof

String log = "";

class C {
  int m1(int v, [String s = "s1"]);

  int m2(int v, {String s = "s2"});

  dynamic noSuchMethod(Invocation inv) {
    for (int i = 0; i < inv.positionalArguments.length; i++) {
      log += "${inv.positionalArguments[i]};";
    }
    for (int i = 0; i < inv.namedArguments.length; i++) {
      log += "s=${inv.namedArguments[Symbol("s")]};";
    }
    return 42;
  }
}

mixin M {
  int m1(int v, [String s = "s1"]);

  int m2(int v, {String s = "s2"});

  dynamic noSuchMethod(Invocation inv) {
    for (int i = 0; i < inv.positionalArguments.length; i++) {
      log += "${inv.positionalArguments[i]};";
    }
    for (int i = 0; i < inv.namedArguments.length; i++) {
      log += "s=${inv.namedArguments[Symbol("s")]};";
    }
    return 42;
  }
}

class MA = Object with M;

main() {
  C().m1(1);
  print(log); // 1;s1;
  log = "";
  C().m2(2);
  print(log); // 2;s=s2;
  log = "";

  MA().m1(1);
  print(log); // 1;
  log = "";
  MA().m2(2);
  print(log); // 2;
}

No this issue on DartPad. DartPad output is

1;s1;
2;s=s2;
1;s1;
2;s=s2;

So, I believe, this is VM issue

Tested on Dart SDK version: 3.2.0-202.0.dev (dev) (Tue Sep 26 21:06:42 2023 -0700) on "windows_x64"

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions