Skip to content

[dart2wasm] Incorrect ParamInfo for non-nullable non-optional named args with no default values #50587

Closed
@osa1

Description

@osa1
class Cat {
  bool eatFood(String food) => true;
}

class MockCat implements Cat {
  dynamic noSuchMethod(Invocation invocation) {
    var arg = invocation.positionalArguments[0];
    return arg is String && arg.isNotEmpty;
  }
}

class MockCat2 extends MockCat {
  noSuchMethod(_);
}

class MockCat3 extends MockCat2 implements Cat {
  bool eatFood(String food, {double amount});

  dynamic noSuchMethod(Invocation invocation) {
    if (invocation.memberName == #scratch) {
      return invocation.positionalArguments.join(',');
    }

    return (invocation.positionalArguments[0] as String).isNotEmpty &&
        invocation.namedArguments[#amount] > 0.5;
  }
}

void main() {
  MockCat mock = new MockCat();
  print((mock as dynamic).eatFood("cat food"));
  print(mock.eatFood(""));

  var mock2 = new MockCat2();
  print(mock2.eatFood("cat food"));

  var mock3 = new MockCat3();
  print(mock3.eatFood("cat food", amount: 0.9));
  print(mock3.eatFood("cat food", amount: 0.3));
}

In this program, the ParamInfo for eatFood selector has a named parameter with NullConstant(null) as the default value of the parameter.

However type of the parameter is f64 and inputs of the Wasm function for this member is [ref #Top, ref Object, f64]. So when we try to initialize the missing non-required named argument with a null value, convertType assumes this is dead code (as null is not a valid f64 value) and generates unreachable.

The problem seems to be the type, which should be nullable. If I print invocation object in noSuchMethod and don't pass amount in the last line, AOT prints {Symbol("amount"): null} as the named arguments. So null should be a valid value for that named argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions