[cfe/ffi] Error on compound constructors
TEST=co19/LibTest/ffi/Struct/Struct_A02_t01 TEST=co19/LibTest/ffi/Union/Union_A03_t01 TEST=co19/LibTest/ffi/Union/Union_A03_t02 TEST=co19/LibTest/ffi/Union/Union_A03_t03 TEST=co19/LibTest/ffi/Union/Union_A04_t01 Closes: https://github.com/dart-lang/sdk/issues/46813 Change-Id: I2a057613a62eccc0de81083a6f63f8ba68430fc9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293684 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
This commit is contained in:
committed by
Commit Queue
parent
6c7be24b24
commit
fa3a72fa7e
@@ -4643,6 +4643,15 @@ Message _withArgumentsFfiCompoundImplementsFinalizable(
|
||||
arguments: {'string': string, 'name': name});
|
||||
}
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Code<Null> codeFfiCreateOfStructOrUnion = messageFfiCreateOfStructOrUnion;
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const MessageCode messageFfiCreateOfStructOrUnion = const MessageCode(
|
||||
"FfiCreateOfStructOrUnion",
|
||||
problemMessage:
|
||||
r"""Subclasses of 'Struct' and 'Union' are backed by native memory, and can't be instantiated by a generative constructor. Try allocating it via allocation, or load from a 'Pointer'.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Template<
|
||||
Message Function(
|
||||
|
||||
@@ -59,6 +59,7 @@ export '../fasta/fasta_codes.dart'
|
||||
LocatedMessage,
|
||||
messageFfiAbiSpecificIntegerInvalid,
|
||||
messageFfiAbiSpecificIntegerMappingInvalid,
|
||||
messageFfiCreateOfStructOrUnion,
|
||||
messageFfiExceptionalReturnNull,
|
||||
messageFfiExpectedConstant,
|
||||
messageFfiLeafCallMustNotReturnHandle,
|
||||
|
||||
@@ -377,6 +377,7 @@ FastaUsageShort/analyzerCode: Fail
|
||||
FastaUsageShort/example: Fail
|
||||
FfiAbiSpecificIntegerInvalid/analyzerCode: Fail
|
||||
FfiAbiSpecificIntegerMappingInvalid/analyzerCode: Fail
|
||||
FfiCreateOfStructOrUnion/analyzerCode: Fail
|
||||
FfiCompoundImplementsFinalizable/analyzerCode: Fail
|
||||
FfiDartTypeMismatch/analyzerCode: Fail
|
||||
FfiEmptyStruct/analyzerCode: Fail
|
||||
|
||||
@@ -4918,6 +4918,11 @@ FfiAbiSpecificIntegerMappingInvalid:
|
||||
problemMessage: "Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a NativeType integer with a fixed size."
|
||||
external: test/ffi_test.dart
|
||||
|
||||
FfiCreateOfStructOrUnion:
|
||||
# Used by dart:ffi
|
||||
problemMessage: "Subclasses of 'Struct' and 'Union' are backed by native memory, and can't be instantiated by a generative constructor. Try allocating it via allocation, or load from a 'Pointer'."
|
||||
external: test/ffi_test.dart
|
||||
|
||||
FfiTypeMismatch:
|
||||
# Used by dart:ffi
|
||||
problemMessage: "Expected type '#type' to be '#type2', which is the Dart type corresponding to '#type3'."
|
||||
|
||||
@@ -22,6 +22,7 @@ augmentation
|
||||
augmentations
|
||||
augmented
|
||||
b
|
||||
backed
|
||||
c
|
||||
cast
|
||||
collide
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:front_end/src/api_unstable/vm.dart'
|
||||
show
|
||||
messageFfiCreateOfStructOrUnion,
|
||||
messageFfiExceptionalReturnNull,
|
||||
messageFfiExpectedConstant,
|
||||
templateFfiDartTypeMismatch,
|
||||
@@ -13,6 +14,7 @@ import 'package:front_end/src/api_unstable/vm.dart'
|
||||
templateFfiExtendsOrImplementsSealedClass,
|
||||
templateFfiNotStatic;
|
||||
|
||||
import 'package:front_end/src/api_prototype/lowering_predicates.dart';
|
||||
import 'package:kernel/ast.dart';
|
||||
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
|
||||
import 'package:kernel/core_types.dart';
|
||||
@@ -116,17 +118,34 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
visitConstructorInvocation(ConstructorInvocation node) {
|
||||
if (_inFfiTearoff) {
|
||||
return node;
|
||||
}
|
||||
final target = node.target;
|
||||
if (hierarchy.isSubclassOf(target.enclosingClass, compoundClass) &&
|
||||
target.name != Name("#fromTypedDataBase")) {
|
||||
diagnosticReporter.report(messageFfiCreateOfStructOrUnion,
|
||||
node.fileOffset, 1, node.location?.file);
|
||||
}
|
||||
return super.visitConstructorInvocation(node);
|
||||
}
|
||||
|
||||
@override
|
||||
visitProcedure(Procedure node) {
|
||||
assert(_inFfiTearoff == false);
|
||||
_inFfiTearoff = (isFfiLibrary &&
|
||||
node.isExtensionMember &&
|
||||
(node == allocationTearoff ||
|
||||
node == asFunctionTearoff ||
|
||||
node == lookupFunctionTearoff ||
|
||||
node == abiSpecificIntegerPointerElementAtTearoff ||
|
||||
node == structPointerElementAtTearoff ||
|
||||
node == unionPointerElementAtTearoff));
|
||||
_inFfiTearoff = ((isFfiLibrary &&
|
||||
node.isExtensionMember &&
|
||||
(node == allocationTearoff ||
|
||||
node == asFunctionTearoff ||
|
||||
node == lookupFunctionTearoff ||
|
||||
node == abiSpecificIntegerPointerElementAtTearoff ||
|
||||
node == structPointerElementAtTearoff ||
|
||||
node == unionPointerElementAtTearoff))) ||
|
||||
// Dart2wasm uses enabledConstructorTearOffLowerings but these are not
|
||||
// users trying to call constructors.
|
||||
isConstructorTearOffLowering(node);
|
||||
final result = super.visitProcedure(node);
|
||||
_inFfiTearoff = false;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user