Revert "[analyzer/ffi] Disallow nullable struct fields"

Revert submission 279511

Reason for revert: Flutter dependencies are using nullable struct
fields and need to be migrated first
https://github.com/flutter/flutter/issues/120260

Reverted changes: /q/submissionid:279510 /q/submissionid:279511

Change-Id: I84d8ec03bc56e4cf9d18ae99954c89ae61eb233a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281601
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
This commit is contained in:
Daco Harkes 2023-02-08 08:51:28 +00:00 committed by Commit Queue
parent 732e4a43d5
commit 035b0c23a9
2 changed files with 1 additions and 16 deletions

View file

@ -6,7 +6,6 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
@ -993,10 +992,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
FfiCode.MISSING_FIELD_TYPE_IN_STRUCT, fields.variables[0].name);
} else {
DartType declaredType = fieldType.typeOrThrow;
if (declaredType.nullabilitySuffix == NullabilitySuffix.question) {
_errorReporter.reportErrorForNode(FfiCode.INVALID_FIELD_TYPE_IN_STRUCT,
fieldType, [fieldType.toSource()]);
} else if (declaredType.isDartCoreInt) {
if (declaredType.isDartCoreInt) {
_validateAnnotations(fieldType, annotations, _PrimitiveDartType.int);
} else if (declaredType.isDartCoreDouble) {
_validateAnnotations(fieldType, annotations, _PrimitiveDartType.double);

View file

@ -43,17 +43,6 @@ class C extends Union {
]);
}
test_instance_invalid3() async {
await assertErrorsInCode(r'''
import 'dart:ffi';
class C extends Struct {
external Pointer? p;
}
''', [
error(FfiCode.INVALID_FIELD_TYPE_IN_STRUCT, 55, 8),
]);
}
test_instance_valid() async {
await assertNoErrorsInCode(r'''
import 'dart:ffi';