Skip to content

Dart2JS: Fatal error paths not treated a such? #33917

Closed
@matanlurey

Description

@matanlurey

Forked from #33372.

I am a bit confused on the output of the following program:

void main(var arg) {
  switch (arg) {
    case 1:
      willThrowNoSuchMethod();
      break;
    case 2:
      willThrowCastError();
      break;
    case 3:
      willThrowTypeError();
      break;
  }
}

void willThrowNoSuchMethod() {
  dynamic x = [];
  x.aMissingMethod();
  return null;
  return null;
}

void willThrowCastError() {
  var x = [];
  List<String> y = x;
  return null;
  return null;
}

void willThrowTypeError() {
  dynamic x = 5;
  String y = x;
  return null;
  return null;
}

... emits ...

main: function(arg) {
  switch (arg) {
    case 1:
      F.willThrowNoSuchMethod();
      break;
    case 2:
      F.willThrowCastError();
      break;
    case 3:
      F.willThrowTypeError();
      break;
  }
},
willThrowNoSuchMethod: function() {
  [].aMissingMethod$0();
  return;
},
willThrowCastError: function() {
  H.assertSubtype([], "$isList", [P.String], "$asList");
  return;
},
willThrowTypeError: function() {
  H.stringTypeCheck(5);
  return;
}

Questions:

  1. Why isn't a NSM error inlined in lieu of [].aMissingMethod$()?
  2. Why isn't a TypeError inlined in lieu of H.assertSubtype?
  3. Why isn't a TypeError inlined in lieu of H.stringTypeCheck?

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