dart-sdk/tests/ffi/coordinate_nnbd_workaround.dart
Daco Harkes 5f68b0bba6 [test/ffi] Test struct workaround for external fields
Make sure the individual getter/setter workaround for structs in NNBD
works. That way structs can be migrated without having to opt in to
the proposed --enable-experiment=external-abstract-variables for
external fields.

Note that this requires dart:ffi users to migrate twice for NNBD, once
to the workaround, and later a cleanup to external fields.

Change-Id: I2a9020ff7df3ebf08e04f71183f9297d87acb1b1
Cq-Include-Trybots:dart/try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153777
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2020-07-09 15:09:21 +00:00

30 lines
749 B
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library FfiTest;
import 'dart:ffi';
import "package:ffi/ffi.dart";
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@Double()
external double get x;
external set x(double v);
@Double()
external double get y;
external set y(double v);
external Pointer<Coordinate> get next;
external set next(Pointer<Coordinate> v);
factory Coordinate.allocate(double x, double y, Pointer<Coordinate> next) {
return allocate<Coordinate>().ref
..x = x
..y = y
..next = next;
}
}