non_ constant_ type_ argument
The type arguments to '{0}' must be known at compile time, so they can't be type parameters.
Description
#The analyzer produces this diagnostic when the type arguments to a method are required to be known at compile time, but a type parameter, whose value can't be known at compile time, is used as a type argument.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because the type argument to
Pointer.asFunction must be known at compile time, but the type parameter
R, which isn't known at compile time, is being used as the type
argument:
import 'dart:ffi';
typedef T = int Function(int);
class C<R extends T> {
void m(Pointer<NativeFunction<T>> p) {
p.asFunction<R>();
}
}
Common fixes
#Remove any uses of type parameters:
import 'dart:ffi';
class C {
void m(Pointer<NativeFunction<Int64 Function(Int64)>> p) {
p.asFunction<int Function(int)>();
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.