Skip to content

Commit

Permalink
#993. Added tests checking that Struct fields cannot have initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Mar 12, 2021
1 parent 53e0635 commit 464da11
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
29 changes: 29 additions & 0 deletions LibTest/ffi/Struct/Struct_A09_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion All field declarations in a Struct subclass declaration must be
* marked external. You cannot create instances of the class, only have it point
* to existing native memory, so there is no memory in which to store non-native
* fields. External fields also cannot be initialized by constructors since no
* Dart object is being created.
*
* @description Checks that all field declarations in a Struct subclass
* declaration cannot have initializers
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";

class S1 extends Struct {
@Int16()
int i = 42;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

void main() {
S1? s1;
}
29 changes: 29 additions & 0 deletions LibTest/ffi/Struct/Struct_A09_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion All field declarations in a Struct subclass declaration must be
* marked external. You cannot create instances of the class, only have it point
* to existing native memory, so there is no memory in which to store non-native
* fields. External fields also cannot be initialized by constructors since no
* Dart object is being created.
*
* @description Checks that all field declarations in a Struct subclass
* declaration cannot have initializers
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";

class S1 extends Struct {
@Double()
double d = 3.14;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

void main() {
S1? s1;
}
28 changes: 28 additions & 0 deletions LibTest/ffi/Struct/Struct_A09_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion All field declarations in a Struct subclass declaration must be
* marked external. You cannot create instances of the class, only have it point
* to existing native memory, so there is no memory in which to store non-native
* fields. External fields also cannot be initialized by constructors since no
* Dart object is being created.
*
* @description Checks that all field declarations in a Struct subclass
* declaration cannot have initializers
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";

class S1 extends Struct {
Pointer<S1> next = new Pointer.fromAddress(42);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

void main() {
S1? s1;
}

0 comments on commit 464da11

Please sign in to comment.