mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:57:35 +00:00
Improve the highlight range for non_positive_array_dimension
Change-Id: Ibd2eabda9adf2489f52fc988c97b5452765cc2a8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213822 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
5f7a18b492
commit
01cf350483
|
@ -975,11 +975,28 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
_errorReporter.reportErrorForNode(
|
||||
FfiCode.SIZE_ANNOTATION_DIMENSIONS, annotation);
|
||||
}
|
||||
// Check dimensions is positive
|
||||
for (int dimension in dimensions) {
|
||||
if (dimension <= 0) {
|
||||
|
||||
// Check dimensions are positive
|
||||
List<AstNode>? getArgumentNodes() {
|
||||
var arguments = annotation.arguments?.arguments;
|
||||
if (arguments != null && arguments.length == 1) {
|
||||
var firstArgument = arguments[0];
|
||||
if (firstArgument is ListLiteral) {
|
||||
return firstArgument.elements;
|
||||
}
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
for (int i = 0; i < dimensions.length; i++) {
|
||||
if (dimensions[i] <= 0) {
|
||||
AstNode errorNode = annotation;
|
||||
var argumentNodes = getArgumentNodes();
|
||||
if (argumentNodes != null && argumentNodes.isNotEmpty) {
|
||||
errorNode = argumentNodes[i];
|
||||
}
|
||||
_errorReporter.reportErrorForNode(
|
||||
FfiCode.NON_POSITIVE_ARRAY_DIMENSION, annotation);
|
||||
FfiCode.NON_POSITIVE_ARRAY_DIMENSION, errorNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,28 +9,13 @@ import '../dart/resolution/context_collection_resolution.dart';
|
|||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(FfiArrayMultiNonPositiveInput);
|
||||
defineReflectiveTests(NonPositiveArrayDimensionTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class FfiArrayMultiNonPositiveInput extends PubPackageResolutionTest {
|
||||
test_multi() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
class MyStruct extends Struct {
|
||||
@Array.multi([1, 2, 3, -4, 5, 6])
|
||||
external Array<Array<Array<Array<Array<Array<Uint8>>>>>> a0;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 54, 33),
|
||||
]);
|
||||
}
|
||||
|
||||
test_negative() async {
|
||||
class NonPositiveArrayDimensionTest extends PubPackageResolutionTest {
|
||||
test_multi_negative() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
|
@ -38,14 +23,25 @@ class MyStruct extends Struct {
|
|||
@Array.multi([-1])
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 54, 18),
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 68, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_non_error() async {
|
||||
test_multi_oneOfMany() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
class MyStruct extends Struct {
|
||||
@Array.multi([1, 2, 3, -4, 5, 6])
|
||||
external Array<Array<Array<Array<Array<Array<Uint8>>>>>> a0;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 77, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_multi_positive() async {
|
||||
await assertNoErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
|
@ -53,12 +49,10 @@ class MyStruct extends Struct {
|
|||
@Array.multi([1])
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_zero() async {
|
||||
test_multi_zero() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
|
@ -66,10 +60,45 @@ class MyStruct extends Struct {
|
|||
@Array.multi([0])
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 54, 17),
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 68, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_single_negative() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
class MyStruct extends Struct {
|
||||
@Array(-12)
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 61, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
test_single_positive() async {
|
||||
await assertNoErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
class MyStruct extends Struct {
|
||||
@Array(1)
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_single_zero() async {
|
||||
await assertErrorsInCode('''
|
||||
import "dart:ffi";
|
||||
|
||||
class MyStruct extends Struct {
|
||||
@Array(0)
|
||||
external Array<Uint8> a0;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.NON_POSITIVE_ARRAY_DIMENSION, 61, 1),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -191,8 +191,6 @@ import 'extra_annotation_on_struct_field_test.dart'
|
|||
as extra_annotation_on_struct_field;
|
||||
import 'extra_positional_arguments_test.dart' as extra_positional_arguments;
|
||||
import 'extra_size_annotation_carray_test.dart' as extra_size_annotation_carray;
|
||||
import 'ffi_array_multi_non_positive_input_test.dart'
|
||||
as ffi_array_multi_non_positive_input_test;
|
||||
import 'ffi_leaf_call_must_not_use_handle_test.dart'
|
||||
as ffi_leaf_call_must_not_use_handle;
|
||||
import 'ffi_native_test.dart' as ffi_native_test;
|
||||
|
@ -488,6 +486,7 @@ import 'non_generative_implicit_constructor_test.dart'
|
|||
import 'non_native_function_type_argument_to_pointer_test.dart'
|
||||
as non_native_function_type_argument_to_pointer;
|
||||
import 'non_null_opt_out_test.dart' as non_null_opt_out;
|
||||
import 'non_positive_array_dimension_test.dart' as non_positive_array_dimension;
|
||||
import 'non_sized_type_argument_test.dart' as non_sized_type_argument;
|
||||
import 'non_type_as_type_argument_test.dart' as non_type_as_type_argument;
|
||||
import 'non_type_in_catch_clause_test.dart' as non_type_in_catch_clause;
|
||||
|
@ -850,7 +849,6 @@ main() {
|
|||
extra_annotation_on_struct_field.main();
|
||||
extra_positional_arguments.main();
|
||||
extra_size_annotation_carray.main();
|
||||
ffi_array_multi_non_positive_input_test.main();
|
||||
ffi_leaf_call_must_not_use_handle.main();
|
||||
ffi_native_test.main();
|
||||
field_in_struct_with_initializer.main();
|
||||
|
@ -1040,6 +1038,7 @@ main() {
|
|||
non_generative_implicit_constructor.main();
|
||||
non_native_function_type_argument_to_pointer.main();
|
||||
non_null_opt_out.main();
|
||||
non_positive_array_dimension.main();
|
||||
non_sized_type_argument.main();
|
||||
non_type_as_type_argument.main();
|
||||
non_type_in_catch_clause.main();
|
||||
|
|
Loading…
Reference in a new issue