blob: 092885091a7b0d82dc09cde8b76e1b2cb281b8ff [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/dart/error/ffi_code.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NonNativeFunctionTypeArgumentToPointerTest);
});
}
@reflectiveTest
class NonNativeFunctionTypeArgumentToPointerTest extends DriverResolutionTest {
test_asFunction_1() async {
await assertErrorsInCode(r'''
import 'dart:ffi';
typedef R = Int8 Function(Int8);
class C {
void f(Pointer<Double> p) {
p.asFunction<R>();
}
}
''', [
error(FfiCode.NON_NATIVE_FUNCTION_TYPE_ARGUMENT_TO_POINTER, 109, 1),
]);
}
test_asFunction_2() async {
await assertErrorsInCode(r'''
import 'dart:ffi';
typedef TPrime = int Function(int);
typedef F = String Function(String);
class C {
void f(Pointer<NativeFunction<TPrime>> p) {
p.asFunction<F>();
}
}
''', [
error(FfiCode.NON_NATIVE_FUNCTION_TYPE_ARGUMENT_TO_POINTER, 165, 1),
]);
}
test_asFunction_F() async {
await assertErrorsInCode(r'''
import 'dart:ffi';
typedef R = int Function(int);
class C<T extends Function> {
void f(Pointer<NativeFunction<T>> p) {
p.asFunction<R>();
}
}
''', [
error(FfiCode.NON_NATIVE_FUNCTION_TYPE_ARGUMENT_TO_POINTER, 138, 1),
]);
}
}