mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
[analyzer/ffi] Error on sizeOf<Handle>()
Test covers both analyzer and CFE throwing an error. (But does not test what error.) Closes: https://github.com/dart-lang/sdk/issues/45100 Change-Id: I8b820347945d88304d3f03d7d03f156b7111db42 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193405 Auto-Submit: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
38d5c5e444
commit
93a187e6c8
|
@ -269,13 +269,13 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
return false;
|
||||
}
|
||||
if (!_isValidFfiNativeType(nativeType.returnType,
|
||||
allowVoid: true, allowEmptyStruct: false)) {
|
||||
allowVoid: true, allowEmptyStruct: false, allowHandle: true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final DartType typeArg in nativeType.normalParameterTypes) {
|
||||
if (!_isValidFfiNativeType(typeArg,
|
||||
allowVoid: false, allowEmptyStruct: false)) {
|
||||
allowVoid: false, allowEmptyStruct: false, allowHandle: true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -288,13 +288,21 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
bool _isValidFfiNativeType(DartType? nativeType,
|
||||
{bool allowVoid = false,
|
||||
bool allowEmptyStruct = false,
|
||||
bool allowArray = false}) {
|
||||
bool allowArray = false,
|
||||
bool allowHandle = false}) {
|
||||
if (nativeType is InterfaceType) {
|
||||
// Is it a primitive integer/double type (or ffi.Void if we allow it).
|
||||
final primitiveType = _primitiveNativeType(nativeType);
|
||||
if (primitiveType != _PrimitiveDartType.none &&
|
||||
(primitiveType != _PrimitiveDartType.void_ || allowVoid)) {
|
||||
return true;
|
||||
switch (primitiveType) {
|
||||
case _PrimitiveDartType.void_:
|
||||
return allowVoid;
|
||||
case _PrimitiveDartType.handle:
|
||||
return allowHandle;
|
||||
case _PrimitiveDartType.double:
|
||||
case _PrimitiveDartType.int:
|
||||
return true;
|
||||
case _PrimitiveDartType.none:
|
||||
// These are the cases below.
|
||||
break;
|
||||
}
|
||||
if (nativeType.isNativeFunction) {
|
||||
return _isValidFfiNativeFunctionType(nativeType.typeArguments.single);
|
||||
|
@ -302,7 +310,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
if (nativeType.isPointer) {
|
||||
final nativeArgumentType = nativeType.typeArguments.single;
|
||||
return _isValidFfiNativeType(nativeArgumentType,
|
||||
allowVoid: true, allowEmptyStruct: true) ||
|
||||
allowVoid: true, allowEmptyStruct: true, allowHandle: true) ||
|
||||
nativeArgumentType.isStructSubtype ||
|
||||
nativeArgumentType.isNativeType;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ void main() {
|
|||
testRefStruct();
|
||||
testSizeOfGeneric();
|
||||
testSizeOfNativeType();
|
||||
testSizeOfHandle();
|
||||
testElementAtGeneric();
|
||||
testElementAtNativeType();
|
||||
}
|
||||
|
@ -636,11 +637,11 @@ void testSizeOfGeneric() {
|
|||
}
|
||||
|
||||
void testSizeOfNativeType() {
|
||||
try {
|
||||
sizeOf(); //# 1301: compile-time error
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
sizeOf(); //# 1301: compile-time error
|
||||
}
|
||||
|
||||
void testSizeOfHandle() {
|
||||
sizeOf<Handle>(); //# 1302: compile-time error
|
||||
}
|
||||
|
||||
void testElementAtGeneric() {
|
||||
|
|
|
@ -58,6 +58,7 @@ void main() {
|
|||
testRefStruct();
|
||||
testSizeOfGeneric();
|
||||
testSizeOfNativeType();
|
||||
testSizeOfHandle();
|
||||
testElementAtGeneric();
|
||||
testElementAtNativeType();
|
||||
}
|
||||
|
@ -634,11 +635,11 @@ void testSizeOfGeneric() {
|
|||
}
|
||||
|
||||
void testSizeOfNativeType() {
|
||||
try {
|
||||
sizeOf(); //# 1301: compile-time error
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
sizeOf(); //# 1301: compile-time error
|
||||
}
|
||||
|
||||
void testSizeOfHandle() {
|
||||
sizeOf<Handle>(); //# 1302: compile-time error
|
||||
}
|
||||
|
||||
void testElementAtGeneric() {
|
||||
|
|
Loading…
Reference in a new issue