@@ -30,8 +30,7 @@ import 'ffi.dart'
30
30
NativeType,
31
31
kNativeTypeIntStart,
32
32
kNativeTypeIntEnd,
33
- FfiTransformer,
34
- optimizedTypes;
33
+ FfiTransformer;
35
34
36
35
/// Checks and replaces calls to dart:ffi struct fields and methods.
37
36
void transformLibraries (
@@ -317,6 +316,8 @@ class _FfiUseSiteTransformer extends FfiTransformer {
317
316
return StaticInvocation (asFunctionInternal,
318
317
Arguments ([node.receiver], types: [dartType, nativeSignature]));
319
318
} else if (target == loadMethod) {
319
+ // TODO(dacoharkes): should load and store be generic?
320
+ // https://github.com/dart-lang/sdk/issues/35902
320
321
final DartType dartType = node.arguments.types[0 ];
321
322
final DartType pointerType = node.receiver.getStaticType (env);
322
323
final DartType nativeType = _pointerTypeGetTypeArg (pointerType);
@@ -326,20 +327,11 @@ class _FfiUseSiteTransformer extends FfiTransformer {
326
327
_ensureNativeTypeSized (nativeType, node, target.name);
327
328
_ensureNativeTypeToDartType (nativeType, dartType, node,
328
329
allowStructs: true );
329
-
330
- // TODO(37773): When moving to extension methods we can get rid of
331
- // this rewiring.
332
- final Class nativeClass = (nativeType as InterfaceType ).classNode;
333
- final NativeType nt = getType (nativeClass);
334
- final typeArguments = [
335
- if (nt == NativeType .kPointer) _pointerTypeGetTypeArg (nativeType)
336
- ];
337
- return StaticInvocation (
338
- optimizedTypes.contains (nt) ? loadMethods[nt] : loadStructMethod,
339
- Arguments ([node.receiver], types: typeArguments));
340
330
} else if (target == storeMethod) {
341
- final Expression storeValue = node.arguments.positional.single;
342
- final DartType dartType = storeValue.getStaticType (env);
331
+ // TODO(dacoharkes): should load and store permitted to be generic?
332
+ // https://github.com/dart-lang/sdk/issues/35902
333
+ final DartType dartType =
334
+ node.arguments.positional[0 ].getStaticType (env);
343
335
final DartType pointerType = node.receiver.getStaticType (env);
344
336
final DartType nativeType = _pointerTypeGetTypeArg (pointerType);
345
337
@@ -349,32 +341,6 @@ class _FfiUseSiteTransformer extends FfiTransformer {
349
341
_ensureNativeTypeValid (nativeType, node);
350
342
_ensureNativeTypeSized (nativeType, node, target.name);
351
343
_ensureNativeTypeToDartType (nativeType, dartType, node);
352
-
353
- // TODO(37773): When moving to extension methods we can get rid of
354
- // this rewiring.
355
- final Class nativeClass = (nativeType as InterfaceType ).classNode;
356
- final NativeType nt = getType (nativeClass);
357
- final typeArguments = [
358
- if (nt == NativeType .kPointer) _pointerTypeGetTypeArg (nativeType)
359
- ];
360
- return StaticInvocation (storeMethods[nt],
361
- Arguments ([node.receiver, storeValue], types: typeArguments));
362
- } else if (target == elementAtMethod) {
363
- // TODO(37773): When moving to extension methods we can get rid of
364
- // this rewiring.
365
- final DartType pointerType = node.receiver.getStaticType (env);
366
- final DartType nativeType = _pointerTypeGetTypeArg (pointerType);
367
- final Class nativeClass = (nativeType as InterfaceType ).classNode;
368
- final NativeType nt = getType (nativeClass);
369
- if (optimizedTypes.contains (nt)) {
370
- final typeArguments = [
371
- if (nt == NativeType .kPointer) _pointerTypeGetTypeArg (nativeType)
372
- ];
373
- return StaticInvocation (
374
- elementAtMethods[nt],
375
- Arguments ([node.receiver, node.arguments.positional[0 ]],
376
- types: typeArguments));
377
- }
378
344
}
379
345
} on _FfiStaticTypeError {
380
346
// It's OK to swallow the exception because the diagnostics issued will
@@ -395,7 +361,9 @@ class _FfiUseSiteTransformer extends FfiTransformer {
395
361
final DartType shouldBeElementType =
396
362
convertNativeTypeToDartType (containerTypeArg, allowStructs);
397
363
if (elementType == shouldBeElementType) return ;
398
- // We disable implicit downcasts, they will go away when NNBD lands.
364
+ // Both subtypes and implicit downcasts are allowed statically.
365
+ if (env.isSubtypeOf (shouldBeElementType, elementType,
366
+ SubtypeCheckMode .ignoringNullabilities)) return ;
399
367
if (env.isSubtypeOf (elementType, shouldBeElementType,
400
368
SubtypeCheckMode .ignoringNullabilities)) return ;
401
369
diagnosticReporter.report (
0 commit comments