From e33b9e2d265a45b6efd2f4eaffc44bf425200a10 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Thu, 16 Jan 2020 17:54:06 +0000 Subject: [PATCH] [vm, test] Update dart_api_impl_test to be nnbd clean Bug: https://github.com/dart-lang/sdk/issues/40170 Fixes: https://github.com/dart-lang/sdk/issues/40170 Change-Id: I8f202da92dc24e471e0516a04c8abc5654e434fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131922 Commit-Queue: Liam Appelbe Reviewed-by: Siva Annamalai --- runtime/vm/dart_api_impl_test.cc | 43 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 1ba6b8242d2..bc23cea0f6d 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -3875,67 +3875,69 @@ TEST_CASE(DartAPI_TypeGetNonParamtericTypes) { } TEST_CASE(DartAPI_TypeGetParameterizedTypes) { + // TODO(dartbug.com/40176): Clean up this test once the API supports NNBD. const char* kScriptChars = "class MyClass0 {\n" "}\n" "\n" "class MyClass1 {\n" "}\n" + "Type type() => T;" "MyClass0 getMyClass0() {\n" " return new MyClass0();\n" "}\n" "Type getMyClass0Type() {\n" - " return new MyClass0().runtimeType;\n" + " return type>();\n" "}\n" "MyClass1 getMyClass1() {\n" " return new MyClass1, List>();\n" "}\n" "Type getMyClass1Type() {\n" - " return new MyClass1, List>().runtimeType;\n" + " return type, List>>();\n" "}\n" "MyClass0 getMyClass0_1() {\n" " return new MyClass0();\n" "}\n" "Type getMyClass0_1Type() {\n" - " return new MyClass0().runtimeType;\n" + " return type>();\n" "}\n" "MyClass1 getMyClass1_1() {\n" " return new MyClass1, List>();\n" "}\n" "Type getMyClass1_1Type() {\n" - " return new MyClass1, List>().runtimeType;\n" - "}\n"; + " return type, List>>();\n" + "}\n" + "Type getIntType() { return int; }\n" + "Type getDoubleType() { return double; }\n" + "Type getListIntType() { return type>(); }\n" + "Type getListType() { return List; }\n"; Dart_Handle corelib = Dart_LookupLibrary(NewString("dart:core")); EXPECT_VALID(corelib); - // First get type objects of some of the basic types used in the test. - Dart_Handle int_type = Dart_GetType(corelib, NewString("int"), 0, NULL); - EXPECT_VALID(int_type); - Dart_Handle double_type = Dart_GetType(corelib, NewString("double"), 0, NULL); - EXPECT_VALID(double_type); - Dart_Handle list_type = Dart_GetType(corelib, NewString("List"), 0, NULL); - EXPECT_VALID(list_type); - Dart_Handle type_args = Dart_NewList(1); - EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); - Dart_Handle list_int_type = - Dart_GetType(corelib, NewString("List"), 1, &type_args); - EXPECT_VALID(list_int_type); - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - bool instanceOf = false; // Now instantiate MyClass0 and MyClass1 types with the same type arguments // used in the code above. - type_args = Dart_NewList(2); + Dart_Handle type_args = Dart_NewList(2); + Dart_Handle int_type = Dart_Invoke(lib, NewString("getIntType"), 0, NULL); + EXPECT_VALID(int_type); EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type)); + Dart_Handle double_type = + Dart_Invoke(lib, NewString("getDoubleType"), 0, NULL); + EXPECT_VALID(double_type); EXPECT_VALID(Dart_ListSetAt(type_args, 1, double_type)); Dart_Handle myclass0_type = Dart_GetType(lib, NewString("MyClass0"), 2, &type_args); EXPECT_VALID(myclass0_type); type_args = Dart_NewList(2); + Dart_Handle list_int_type = + Dart_Invoke(lib, NewString("getListIntType"), 0, NULL); + EXPECT_VALID(list_int_type); EXPECT_VALID(Dart_ListSetAt(type_args, 0, list_int_type)); + Dart_Handle list_type = Dart_Invoke(lib, NewString("getListType"), 0, NULL); + EXPECT_VALID(list_type); EXPECT_VALID(Dart_ListSetAt(type_args, 1, list_type)); Dart_Handle myclass1_type = Dart_GetType(lib, NewString("MyClass1"), 2, &type_args); @@ -3947,6 +3949,7 @@ TEST_CASE(DartAPI_TypeGetParameterizedTypes) { // MyClass0 type. Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL); EXPECT_VALID(type0_obj); + bool instanceOf = false; EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceOf)); EXPECT(instanceOf); type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL);