Skip to content

Commit 089a435

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
[dart2js] Add subtyping for identical interface names without explicit type rule.
Change-Id: I0db1ff88e6fcb6a5e3f7615aa588afb473a77a16 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106820 Commit-Queue: Mayank Patke <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent f490398 commit 089a435

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

sdk/lib/_internal/js_runtime/lib/rti.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,19 @@ bool _isSubtype(universe, Rti s, var sEnv, Rti t, var tEnv) {
984984
assert(Rti._getKind(t) == Rti.kindInterface);
985985
String sName = Rti._getInterfaceName(s);
986986
String tName = Rti._getInterfaceName(t);
987-
// TODO(fishythefish): Handle identical names.
987+
988+
if (sName == tName) {
989+
var sArgs = Rti._getInterfaceTypeArguments(s);
990+
var tArgs = Rti._getInterfaceTypeArguments(t);
991+
int length = _Utils.arrayLength(sArgs);
992+
assert(length == _Utils.arrayLength(tArgs));
993+
for (int i = 0; i < length; i++) {
994+
Rti sArg = _castToRti(_Utils.arrayAt(sArgs, i));
995+
Rti tArg = _castToRti(_Utils.arrayAt(tArgs, i));
996+
if (!_isSubtype(universe, sArg, sEnv, tArg, tEnv)) return false;
997+
}
998+
return true;
999+
}
9881000

9891001
// TODO(fishythefish): Should we recursively attempt to find supertypes?
9901002
var rule = _Universe.findRule(universe, sName);
@@ -998,7 +1010,7 @@ bool _isSubtype(universe, Rti s, var sEnv, Rti t, var tEnv) {
9981010
String recipe = _Utils.arrayAt(supertypeArgs, i);
9991011
Rti supertypeArg = _Universe.evalInEnvironment(universe, s, recipe);
10001012
Rti tArg = _castToRti(_Utils.arrayAt(tArgs, i));
1001-
if (!isSubtype(universe, supertypeArg, tArg)) return false;
1013+
if (!_isSubtype(universe, supertypeArg, sEnv, tArg, tEnv)) return false;
10021014
}
10031015

10041016
return true;

tests/compiler/dart2js_extra/rti/subtype_test.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const typeRulesJson = r'''
1313
"CodeUnits": {
1414
"List": ["int"],
1515
"Iterable": ["int"]
16-
},
17-
"Object": {"Object": []}
16+
}
1817
}
1918
''';
2019
final typeRules = JS('=Object', 'JSON.parse(#)', typeRulesJson);
@@ -29,8 +28,26 @@ main() {
2928
void runTests() {
3029
strictSubtype('List<CodeUnits>', 'Iterable<List<int>>');
3130
strictSubtype('CodeUnits', 'Iterable<num>');
31+
strictSubtype('Iterable<int>', 'Iterable<num>');
3232
unrelated('int', 'CodeUnits');
33+
equivalent('double', 'double');
3334
equivalent('Object', 'Object');
35+
equivalent('@', '@');
36+
equivalent('~', '~');
37+
equivalent('1&', '1&');
38+
equivalent('List<int>', 'List<int>');
39+
//equivalent('Object', '@');
40+
//equivalent('Object', '~');
41+
//equivalent('Object', '1&');
42+
equivalent('@', '~');
43+
equivalent('@', '1&');
44+
equivalent('~', '1&');
45+
//equivalent('List<Object>', 'List<@>');
46+
//equivalent('List<Object>', 'List<~>');
47+
//equivalent('List<Object>', 'List<1&>');
48+
equivalent('List<@>', 'List<~>');
49+
equivalent('List<@>', 'List<1&>');
50+
equivalent('List<~>', 'List<1&>');
3451
}
3552

3653
void strictSubtype(String s, String t) {

0 commit comments

Comments
 (0)