mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Migrate language_2/typedef to NNBD.
Change-Id: I415eb8b53e7808c9a09cbc725a422f432f084f66 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151924 Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com> Reviewed-by: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
parent
5f0a94bc12
commit
d872aea6a6
9 changed files with 290 additions and 0 deletions
19
tests/language/typedef/bad_typedef_runtime_test.dart
Normal file
19
tests/language/typedef/bad_typedef_runtime_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// Copyright (c) 2016, 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.
|
||||
// Dart test for a function type test that cannot be eliminated at compile time.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
typedef int H(
|
||||
Function
|
||||
|
||||
x);
|
||||
|
||||
main() {
|
||||
bool b = true;
|
||||
Expect.isFalse(b is H);
|
||||
}
|
19
tests/language/typedef/bad_typedef_test.dart
Normal file
19
tests/language/typedef/bad_typedef_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
// Dart test for a function type test that cannot be eliminated at compile time.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
typedef int H(
|
||||
Function
|
||||
Function
|
||||
x);
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
|
||||
// [cfe] Expected ')' before this.
|
||||
|
||||
main() {
|
||||
bool b = true;
|
||||
Expect.isFalse(b is H);
|
||||
}
|
13
tests/language/typedef/check_bounds_generic_test.dart
Normal file
13
tests/language/typedef/check_bounds_generic_test.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2018, 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.
|
||||
|
||||
// Check that typedef type parameters are verified to satisfy their bounds.
|
||||
|
||||
typedef F<T extends num> = T Function<U>(T x);
|
||||
|
||||
void g(/*@compile-error=unspecified*/ F<String>? f) {}
|
||||
|
||||
main() {
|
||||
g(null);
|
||||
}
|
13
tests/language/typedef/check_bounds_test.dart
Normal file
13
tests/language/typedef/check_bounds_test.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2018, 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.
|
||||
|
||||
// Check that typedef type parameters are verified to satisfy their bounds.
|
||||
|
||||
typedef T F<T extends num>(T x);
|
||||
|
||||
void g(/*@compile-error=unspecified*/ F<String>? f) {}
|
||||
|
||||
main() {
|
||||
g(null);
|
||||
}
|
14
tests/language/typedef/check_bounds_unused_test.dart
Normal file
14
tests/language/typedef/check_bounds_unused_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2018, 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.
|
||||
|
||||
// Check that typedef type parameters are verified to satisfy their bounds, even
|
||||
// if the type parameter in question isn't used by the typedef.
|
||||
|
||||
typedef void F<T extends num>();
|
||||
|
||||
void g(/*@compile-error=unspecified*/ F<String>? f) {}
|
||||
|
||||
main() {
|
||||
g(null);
|
||||
}
|
5
tests/language/typedef/class_in_other_file_helper.dart
Normal file
5
tests/language/typedef/class_in_other_file_helper.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
|
||||
class Bar {}
|
13
tests/language/typedef/class_in_other_file_test.dart
Normal file
13
tests/language/typedef/class_in_other_file_test.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
|
||||
// This has crashed DDC with Kernel because of a
|
||||
// "Concurrent modification during iteration" exception.
|
||||
|
||||
import 'class_in_other_file_helper.dart';
|
||||
|
||||
typedef bool Foo1(bool baz);
|
||||
typedef bool Foo2(Bar baz);
|
||||
|
||||
main() {}
|
69
tests/language/typedef/cyclic_test.dart
Normal file
69
tests/language/typedef/cyclic_test.dart
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// Check that cyclic reference of a typedef is a compile-time error.
|
||||
|
||||
// To test various cyclic references the definition of the [:typedef A():] is
|
||||
// split over several lines:
|
||||
typedef
|
||||
|
||||
// Cyclic through return type.
|
||||
A //# 01: compile-time error
|
||||
|
||||
A // The name of the typedef
|
||||
|
||||
// Cyclic through type variable bound.
|
||||
<T extends A> //# 10: compile-time error
|
||||
|
||||
// Cyclic through generic type variable bound.
|
||||
<T extends List<A>> //# 11: compile-time error
|
||||
|
||||
(// The left parenthesis of the typedef arguments.
|
||||
|
||||
// Cyclic through parameter type.
|
||||
A a //# 02: compile-time error
|
||||
|
||||
// Cyclic through optional parameter type.
|
||||
[A a] //# 03: compile-time error
|
||||
|
||||
// Cyclic through named parameter type.
|
||||
{A a} //# 04: compile-time error
|
||||
|
||||
// Cyclic through generic parameter type.
|
||||
List<A> a //# 05: compile-time error
|
||||
|
||||
// Cyclic through return type of function typed parameter.
|
||||
A f() //# 06: compile-time error
|
||||
|
||||
// Cyclic through parameter type of function typed parameter.
|
||||
f(A a) //# 07: compile-time error
|
||||
|
||||
// Cyclic through another typedef.
|
||||
B b //# 08: compile-time error
|
||||
|
||||
// Cyclic through another more typedefs.
|
||||
C c //# 09: compile-time error
|
||||
|
||||
// Reference through a class is not a cyclic self-reference.
|
||||
Class c //# 12: ok
|
||||
|
||||
// Reference through a class type bound is not a cyclic self-reference.
|
||||
Class c //# 13: compile-time error
|
||||
|
||||
); // The right parenthesis of the typedef arguments.
|
||||
|
||||
typedef B(A a);
|
||||
typedef C(B b);
|
||||
|
||||
class Class
|
||||
<T extends A> //# 13: continued
|
||||
{
|
||||
A? a; //# 12: continued
|
||||
}
|
||||
|
||||
void testA(A? a) {}
|
||||
|
||||
void main() {
|
||||
testA(null);
|
||||
}
|
125
tests/language/typedef/is_test.dart
Normal file
125
tests/language/typedef/is_test.dart
Normal file
|
@ -0,0 +1,125 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Test is-test of typedefs with optional and named parameters.
|
||||
|
||||
typedef int Func1(int a);
|
||||
typedef int Func2(int a, [int b]);
|
||||
typedef int Func3(int a, [int b, int c]);
|
||||
typedef int Func4([int a, int b, int c]);
|
||||
typedef int Func5(int a, {int b});
|
||||
typedef int Func6(int a, {int b, int c});
|
||||
typedef int Func7({int a, int b, int c});
|
||||
|
||||
void main() {
|
||||
int func1(int i) => -1;
|
||||
Expect.isTrue(func1 is Func1);
|
||||
Expect.isFalse(func1 is Func2);
|
||||
Expect.isFalse(func1 is Func3);
|
||||
Expect.isFalse(func1 is Func4);
|
||||
Expect.isFalse(func1 is Func5);
|
||||
Expect.isFalse(func1 is Func6);
|
||||
Expect.isFalse(func1 is Func7);
|
||||
|
||||
int func2(int i, int j) => -1;
|
||||
Expect.isFalse(func2 is Func1);
|
||||
Expect.isFalse(func2 is Func2);
|
||||
Expect.isFalse(func2 is Func3);
|
||||
Expect.isFalse(func2 is Func4);
|
||||
Expect.isFalse(func2 is Func5);
|
||||
Expect.isFalse(func2 is Func6);
|
||||
Expect.isFalse(func2 is Func7);
|
||||
|
||||
int func3(int i, int j, int k) => -1;
|
||||
Expect.isFalse(func3 is Func1);
|
||||
Expect.isFalse(func3 is Func2);
|
||||
Expect.isFalse(func3 is Func3);
|
||||
Expect.isFalse(func3 is Func4);
|
||||
Expect.isFalse(func3 is Func5);
|
||||
Expect.isFalse(func3 is Func6);
|
||||
Expect.isFalse(func3 is Func7);
|
||||
|
||||
int func4(int i, [int j = -1]) => -1;
|
||||
Expect.isTrue(func4 is Func1);
|
||||
Expect.isTrue(func4 is Func2);
|
||||
Expect.isFalse(func4 is Func3);
|
||||
Expect.isFalse(func4 is Func4);
|
||||
Expect.isFalse(func4 is Func5);
|
||||
Expect.isFalse(func4 is Func6);
|
||||
Expect.isFalse(func4 is Func7);
|
||||
|
||||
int func5(int i, [int j = -1, int k = -1]) => -1;
|
||||
Expect.isTrue(func5 is Func1);
|
||||
Expect.isTrue(func5 is Func2);
|
||||
Expect.isTrue(func5 is Func3);
|
||||
Expect.isFalse(func5 is Func4);
|
||||
Expect.isFalse(func5 is Func5);
|
||||
Expect.isFalse(func5 is Func6);
|
||||
Expect.isFalse(func5 is Func7);
|
||||
|
||||
int func6([int i = -1, int j = -1, int k = -1]) => -1;
|
||||
Expect.isTrue(func6 is Func1);
|
||||
Expect.isTrue(func6 is Func2);
|
||||
Expect.isTrue(func6 is Func3);
|
||||
Expect.isTrue(func6 is Func4);
|
||||
Expect.isFalse(func6 is Func5);
|
||||
Expect.isFalse(func6 is Func6);
|
||||
Expect.isFalse(func6 is Func7);
|
||||
|
||||
int func7(int i, {int j = -1}) => -1;
|
||||
Expect.isTrue(func7 is Func1);
|
||||
Expect.isFalse(func7 is Func2);
|
||||
Expect.isFalse(func7 is Func3);
|
||||
Expect.isFalse(func7 is Func4);
|
||||
Expect.isFalse(func7 is Func5);
|
||||
Expect.isFalse(func7 is Func6);
|
||||
Expect.isFalse(func7 is Func7);
|
||||
|
||||
int func8(int i, {int b = -1}) => -1;
|
||||
Expect.isTrue(func8 is Func1);
|
||||
Expect.isFalse(func8 is Func2);
|
||||
Expect.isFalse(func8 is Func3);
|
||||
Expect.isFalse(func8 is Func4);
|
||||
Expect.isTrue(func8 is Func5);
|
||||
Expect.isFalse(func8 is Func6);
|
||||
Expect.isFalse(func8 is Func7);
|
||||
|
||||
int func9(int i, {int b = -1, int c = -1}) => -1;
|
||||
Expect.isTrue(func9 is Func1);
|
||||
Expect.isFalse(func9 is Func2);
|
||||
Expect.isFalse(func9 is Func3);
|
||||
Expect.isFalse(func9 is Func4);
|
||||
Expect.isTrue(func9 is Func5);
|
||||
Expect.isTrue(func9 is Func6);
|
||||
Expect.isFalse(func9 is Func7);
|
||||
|
||||
int func10(int i, {int c = -1, int b = -1}) => -1;
|
||||
Expect.isTrue(func10 is Func1);
|
||||
Expect.isFalse(func10 is Func2);
|
||||
Expect.isFalse(func10 is Func3);
|
||||
Expect.isFalse(func10 is Func4);
|
||||
Expect.isTrue(func10 is Func5);
|
||||
Expect.isTrue(func10 is Func6);
|
||||
Expect.isFalse(func10 is Func7);
|
||||
|
||||
int func11({int a = -1, int b = -1, int c = -1}) => -1;
|
||||
Expect.isFalse(func11 is Func1);
|
||||
Expect.isFalse(func11 is Func2);
|
||||
Expect.isFalse(func11 is Func3);
|
||||
Expect.isFalse(func11 is Func4);
|
||||
Expect.isFalse(func11 is Func5);
|
||||
Expect.isFalse(func11 is Func6);
|
||||
Expect.isTrue(func11 is Func7);
|
||||
|
||||
int func12({int c = -1, int a = -1, int b = -1}) => -1;
|
||||
Expect.isFalse(func12 is Func1);
|
||||
Expect.isFalse(func12 is Func2);
|
||||
Expect.isFalse(func12 is Func3);
|
||||
Expect.isFalse(func12 is Func4);
|
||||
Expect.isFalse(func12 is Func5);
|
||||
Expect.isFalse(func12 is Func6);
|
||||
Expect.isTrue(func12 is Func7);
|
||||
}
|
Loading…
Reference in a new issue