Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f0f78da

Browse files
author
Dart CI
committed
Version 2.16.0-31.0.dev
Merge commit '00ea62f71368306b01f593d055af011bc0d57f1b' into 'dev'
2 parents 6cc51d7 + 00ea62f commit f0f78da

File tree

7 files changed

+128
-27
lines changed

7 files changed

+128
-27
lines changed

pkg/vm/lib/transformations/ffi/common.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,22 +725,31 @@ class FfiTransformer extends Transformer {
725725
/// Returns the single element type nested type argument of `Array`.
726726
///
727727
/// `Array<Array<Array<Int8>>>` -> `Int8`.
728+
///
729+
/// `Array<Array<Array<Unknown>>>` -> [InvalidType].
728730
DartType arraySingleElementType(DartType dartType) {
729731
InterfaceType elementType = dartType as InterfaceType;
730732
while (elementType.classNode == arrayClass) {
731-
elementType = elementType.typeArguments[0] as InterfaceType;
733+
final elementTypeAny = elementType.typeArguments[0];
734+
if (elementTypeAny is InvalidType) {
735+
return elementTypeAny;
736+
}
737+
elementType = elementTypeAny as InterfaceType;
732738
}
733739
return elementType;
734740
}
735741

736742
/// Returns the number of dimensions of `Array`.
737743
///
738744
/// `Array<Array<Array<Int8>>>` -> 3.
745+
///
746+
/// `Array<Array<Array<Unknown>>>` -> 3.
739747
int arrayDimensions(DartType dartType) {
740-
InterfaceType elementType = dartType as InterfaceType;
748+
DartType elementType = dartType;
741749
int dimensions = 0;
742-
while (elementType.classNode == arrayClass) {
743-
elementType = elementType.typeArguments[0] as InterfaceType;
750+
while (
751+
elementType is InterfaceType && elementType.classNode == arrayClass) {
752+
elementType = elementType.typeArguments[0];
744753
dimensions++;
745754
}
746755
return dimensions;

pkg/vm/lib/transformations/ffi/definitions.dart

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ class _FfiDefinitionTransformer extends FfiTransformer {
146146
final sizeAnnotations = _getArraySizeAnnotations(f);
147147
if (sizeAnnotations.length == 1) {
148148
final singleElementType = arraySingleElementType(type);
149-
if (isCompoundSubtype(singleElementType)) {
150-
final clazz = (singleElementType as InterfaceType).classNode;
149+
if (singleElementType is InterfaceType &&
150+
isCompoundSubtype(singleElementType)) {
151+
final clazz = singleElementType.classNode;
151152
dependencies.add(clazz);
152153
}
153154
}
@@ -403,24 +404,31 @@ class _FfiDefinitionTransformer extends FfiTransformer {
403404
final sizeAnnotations = _getArraySizeAnnotations(f);
404405
if (sizeAnnotations.length == 1) {
405406
final singleElementType = arraySingleElementType(type);
406-
if (isCompoundSubtype(singleElementType)) {
407-
final clazz = (singleElementType as InterfaceType).classNode;
408-
_checkPacking(node, packing, clazz, f);
409-
}
410-
final dimensions = sizeAnnotations.single;
411-
if (arrayDimensions(type) != dimensions.length) {
412-
diagnosticReporter.report(
413-
templateFfiSizeAnnotationDimensions
414-
.withArguments(f.name.text),
415-
f.fileOffset,
416-
f.name.text.length,
417-
f.fileUri);
418-
}
419-
for (var dimension in dimensions) {
420-
if (dimension < 0) {
421-
diagnosticReporter.report(messageNonPositiveArrayDimensions,
422-
f.fileOffset, f.name.text.length, f.fileUri);
423-
success = false;
407+
if (singleElementType is! InterfaceType) {
408+
assert(singleElementType is InvalidType);
409+
// This class is invalid, but continue reporting other errors on it.
410+
// An error on the type will already have been reported.
411+
success = false;
412+
} else {
413+
if (isCompoundSubtype(singleElementType)) {
414+
final clazz = singleElementType.classNode;
415+
_checkPacking(node, packing, clazz, f);
416+
}
417+
final dimensions = sizeAnnotations.single;
418+
if (arrayDimensions(type) != dimensions.length) {
419+
diagnosticReporter.report(
420+
templateFfiSizeAnnotationDimensions
421+
.withArguments(f.name.text),
422+
f.fileOffset,
423+
f.name.text.length,
424+
f.fileUri);
425+
}
426+
for (var dimension in dimensions) {
427+
if (dimension < 0) {
428+
diagnosticReporter.report(messageNonPositiveArrayDimensions,
429+
f.fileOffset, f.name.text.length, f.fileUri);
430+
success = false;
431+
}
424432
}
425433
}
426434
} else {
@@ -568,8 +576,15 @@ class _FfiDefinitionTransformer extends FfiTransformer {
568576
if (sizeAnnotations.length == 1) {
569577
final arrayDimensions = sizeAnnotations.single;
570578
if (this.arrayDimensions(dartType) == arrayDimensions.length) {
571-
type = NativeTypeCfe(this, dartType,
572-
compoundCache: compoundCache, arrayDimensions: arrayDimensions);
579+
final elementType = arraySingleElementType(dartType);
580+
if (elementType is! InterfaceType) {
581+
assert(elementType is InvalidType);
582+
type = InvalidNativeTypeCfe("Invalid element type.");
583+
} else {
584+
type = NativeTypeCfe(this, dartType,
585+
compoundCache: compoundCache,
586+
arrayDimensions: arrayDimensions);
587+
}
573588
} else {
574589
type = InvalidNativeTypeCfe("Invalid array dimensions.");
575590
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// SharedObjects=ffi_test_functions
6+
7+
import 'dart:ffi';
8+
9+
class A extends Struct {
10+
@Array.multi([16])
11+
external Array<Int8> a;
12+
13+
// This should not crash the FFI transform.
14+
@Array.multi([16]) //# 1: compile-time error
15+
external Array<Unknown> b; //# 1: compile-time error
16+
}
17+
18+
main() {}

tests/ffi/regress_47673_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// SharedObjects=ffi_test_functions
6+
7+
import 'dart:ffi';
8+
9+
typedef T = Int64;
10+
11+
class A extends Struct {
12+
@Array.multi([16])
13+
external Array<T> b;
14+
}
15+
16+
main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// SharedObjects=ffi_test_functions
6+
7+
// @dart=2.9
8+
9+
import 'dart:ffi';
10+
11+
class A extends Struct {
12+
@Array.multi([16])
13+
Array<Int8> a;
14+
15+
// This should not crash the FFI transform.
16+
@Array.multi([16]) //# 1: compile-time error
17+
Array<Unknown> b; //# 1: compile-time error
18+
}
19+
20+
main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// SharedObjects=ffi_test_functions
6+
7+
// @dart=2.9
8+
9+
import 'dart:ffi';
10+
11+
typedef T = Int64; //# 1: compile-time error
12+
13+
class A extends Struct {
14+
@Array.multi([16])
15+
Array<Int8> a;
16+
17+
// In language version 2.12 we do not support non-function typedefs.
18+
// This should not crash the FFI transform.
19+
@Array.multi([16]) //# 1: compile-time error
20+
Array<T> b; //# 1: compile-time error
21+
}
22+
23+
main() {}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 16
2929
PATCH 0
30-
PRERELEASE 30
30+
PRERELEASE 31
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)