Skip to content

Commit dd9adeb

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dartdevc] Fixes to support un-forking dart:_runtime
- Cleanup some instances of `core.Type._check()` from generated code. - Remove assertions to avoid a bootstrap ordering issue. - Ensure testing for FutureOr in the SDK before async.FutureOr has been loaded returns false. - Make the Null Safety strict mode option false by default. Issue: #40266 Change-Id: I109432ed5226d8187b600c1d4ba6264d9b2f6a9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135380 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent 84ff9e5 commit dd9adeb

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ String? _argumentErrors(FunctionType type, List actuals, namedActuals) {
178178
// Verify that all required named parameters are provided an argument.
179179
Iterable requiredNames = getOwnPropertyNames(requiredNamed);
180180
if (requiredNames.length > 0 && namedActuals == null) {
181-
if (!JS<bool>('', 'dart.__strictSubtypeChecks')) {
181+
if (!_strictSubtypeChecks) {
182182
_warn("Dynamic call with missing required named arguments.");
183183
} else {
184184
return "Dynamic call with missing required named arguments.";
185185
}
186186
}
187-
if (JS<bool>('', 'dart.__strictSubtypeChecks')) {
187+
if (_strictSubtypeChecks) {
188188
for (var name in requiredNames) {
189189
if (!JS<bool>('!', '#.hasOwnProperty(#)', namedActuals, name)) {
190-
if (!JS<bool>('', 'dart.__strictSubtypeChecks')) {
190+
if (!_strictSubtypeChecks) {
191191
_warn("Dynamic call with missing required named argument '$name'.");
192192
} else {
193193
return "Dynamic call with missing required named argument '$name'.";

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
/// This library defines the representation of runtime types.
66
part of dart._runtime;
77

8+
bool _strictSubtypeChecks = false;
9+
810
/// Sets the mode of the runtime subtype checks.
911
///
1012
/// Changing the mode after any calls to dart.isSubtype() is not supported.
1113
void strictSubtypeChecks(bool flag) {
12-
JS('', 'dart.__strictSubtypeChecks = #', flag);
14+
_strictSubtypeChecks = flag;
1315
}
1416

1517
final metadata = JS('', 'Symbol("metadata")');
@@ -256,7 +258,7 @@ Object nullable(type) {
256258
return JS<NullableType>('!', '#[#]', type, _cachedNullable);
257259
}
258260
// Cache a canonical nullable version of this type on this type.
259-
var cachedType = NullableType(type);
261+
var cachedType = NullableType(JS<Type>('!', '#', type));
260262
JS('', '#[#] = #', type, _cachedNullable, cachedType);
261263
return cachedType;
262264
}
@@ -276,7 +278,7 @@ Object legacy(type) {
276278
return JS<LegacyType>('!', '#[#]', type, _cachedLegacy);
277279
}
278280
// Cache a canonical legacy version of this type on this type.
279-
var cachedType = LegacyType(type);
281+
var cachedType = LegacyType(JS<Type>('!', '#', type));
280282
JS('', '#[#] = #', type, _cachedLegacy, cachedType);
281283
return cachedType;
282284
}
@@ -285,9 +287,7 @@ Object legacy(type) {
285287
class NullableType extends DartType {
286288
final Type type;
287289

288-
NullableType(this.type)
289-
: assert(type is! NullableType),
290-
assert(type is! LegacyType);
290+
NullableType(this.type);
291291

292292
@override
293293
String get name => '$type?';
@@ -313,9 +313,7 @@ class NullableType extends DartType {
313313
class LegacyType extends DartType {
314314
final Type type;
315315

316-
LegacyType(this.type)
317-
: assert(type is! LegacyType),
318-
assert(type is! NullableType);
316+
LegacyType(this.type);
319317

320318
@override
321319
String get name => '$type';
@@ -328,7 +326,7 @@ class LegacyType extends DartType {
328326
if (obj == null) {
329327
// Object and Never are the only legacy types that should return true if
330328
// obj is `null`.
331-
return type == unwrapType(Object) || type == unwrapType(Never);
329+
return JS<bool>('!', '# === # || # === #', type, Object, type, never_);
332330
}
333331
return JS<bool>('!', '#.is(#)', type, obj);
334332
}
@@ -1172,7 +1170,7 @@ bool isSubtypeOf(Object t1, Object t2) {
11721170
}
11731171
var validSubtype = _isSubtype(t1, t2, true);
11741172

1175-
if (!validSubtype && !JS<bool>('!', 'dart.__strictSubtypeChecks')) {
1173+
if (!validSubtype && !_strictSubtypeChecks) {
11761174
validSubtype = _isSubtype(t1, t2, false);
11771175
if (validSubtype) {
11781176
// TODO(nshahan) Need more information to be helpful here.
@@ -1205,20 +1203,22 @@ bool _isTop(type) {
12051203

12061204
/// Returns `true` if [type] represents a nullable (question, ?) type.
12071205
@notNull
1208-
bool _isNullable(Type type) => JS<bool>('!', '$type instanceof $NullableType');
1206+
bool _isNullable(type) => JS<bool>('!', '# instanceof #', type, NullableType);
12091207

12101208
/// Returns `true` if [type] represents a legacy (star, *) type.
12111209
@notNull
1212-
bool _isLegacy(Type type) => JS<bool>('!', '$type instanceof $LegacyType');
1210+
bool _isLegacy(type) => JS<bool>('!', '# instanceof #', type, LegacyType);
12131211

12141212
/// Returns `true` if [type] is the [Null] type.
12151213
@notNull
1216-
bool _isNullType(Object type) =>
1217-
JS<bool>('!', '# === #', type, unwrapType(Null));
1214+
bool _isNullType(type) => JS<bool>('!', '# === #', type, unwrapType(Null));
12181215

12191216
@notNull
1220-
bool _isFutureOr(type) =>
1221-
JS<bool>('!', '# === #', getGenericClass(type), getGenericClass(FutureOr));
1217+
bool _isFutureOr(type) {
1218+
var genericClass = getGenericClass(type);
1219+
return JS<bool>('!', '# && # === #', genericClass, genericClass,
1220+
getGenericClass(FutureOr));
1221+
}
12221222

12231223
bool _isSubtype(t1, t2, bool strictMode) => JS('bool', '''(() => {
12241224
if (!$strictMode) {

0 commit comments

Comments
 (0)