1 | // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "include/dart_api.h" |
6 | #include "vm/unit_test.h" |
7 | |
8 | namespace dart { |
9 | |
10 | #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
11 | |
12 | TEST_CASE(Mixin_PrivateSuperResolution) { |
13 | // clang-format off |
14 | Dart_SourceFile sourcefiles[] = { |
15 | { |
16 | "file:///test-app.dart" , |
17 | "class A {\n" |
18 | " _bar() => 42;\n" |
19 | "}\n" |
20 | "class M extends A {\n" |
21 | " bar() => -1;\n" |
22 | "}\n" |
23 | "class B extends A {\n" |
24 | " foo() => 6;\n" |
25 | "}\n" |
26 | "class C extends B with M {\n" |
27 | " bar() => super._bar();\n" |
28 | "}\n" |
29 | "main() {\n" |
30 | " return new C().bar();\n" |
31 | "}\n" , |
32 | }}; |
33 | // clang-format on |
34 | |
35 | Dart_Handle lib = TestCase::LoadTestScriptWithDFE( |
36 | sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles, |
37 | /* resolver= */ NULL, /* finalize= */ true, /* incrementally= */ true); |
38 | EXPECT_VALID(lib); |
39 | Dart_Handle result = Dart_Invoke(lib, NewString("main" ), 0, NULL); |
40 | int64_t value = 0; |
41 | result = Dart_IntegerToInt64(result, &value); |
42 | EXPECT_VALID(result); |
43 | EXPECT_EQ(42, value); |
44 | } |
45 | |
46 | TEST_CASE(Mixin_PrivateSuperResolutionCrossLibraryShouldFail) { |
47 | // clang-format off |
48 | Dart_SourceFile sourcefiles[] = { |
49 | { |
50 | "file:///test-app.dart" , |
51 | "import 'test-lib.dart';\n" |
52 | "class D extends B with M {\n" |
53 | " bar() => super._bar();\n" |
54 | "}\n" |
55 | "main() {\n" |
56 | " try {\n" |
57 | " return new D().bar();\n" |
58 | " } catch (e) {\n" |
59 | " return e.toString().split('\\n').first;\n" |
60 | " }\n" |
61 | "}\n" , |
62 | }, |
63 | { |
64 | "file:///test-lib.dart" , |
65 | "class A {\n" |
66 | " foo() => 4;\n" |
67 | " _bar() => 42;\n" |
68 | "}\n" |
69 | "class M extends A {\n" |
70 | " bar() => -1;\n" |
71 | "}\n" |
72 | "class B extends A {\n" |
73 | " foo() => 6;\n" |
74 | "}\n" |
75 | "class C extends B with M {\n" |
76 | " bar() => super._bar();\n" |
77 | "}\n" |
78 | }, |
79 | { |
80 | "file:///.packages" , "untitled:/" |
81 | }}; |
82 | // clang-format on |
83 | |
84 | Dart_Handle lib = TestCase::LoadTestScriptWithDFE( |
85 | sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles, |
86 | /* resolver= */ NULL, /* finalize= */ true, /* incrementally= */ true); |
87 | EXPECT_ERROR(lib, "Error: Superclass has no method named '_bar'." ); |
88 | } |
89 | #endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
90 | |
91 | } // namespace dart |
92 | |