|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | // Test that `createStaticInteropMock` checks for extension member conflicts.
|
| 6 | +// We should only require users to implement one of these conflicts (or a |
| 7 | +// getter/setter pair). |
6 | 8 |
|
7 | 9 | import 'package:js/js.dart';
|
8 | 10 | import 'package:js/js_util.dart';
|
9 | 11 |
|
10 |
| -class EmptyDart {} |
11 |
| - |
12 | 12 | @JS()
|
13 | 13 | @staticInterop
|
14 |
| -class Method {} |
| 14 | +class SameKindConflict {} |
15 | 15 |
|
16 |
| -extension on Method { |
17 |
| - external void member(); |
| 16 | +extension E1 on SameKindConflict { |
| 17 | + external int get getter; |
| 18 | + external set setter(int val); |
| 19 | + external int method(); |
18 | 20 | }
|
19 | 21 |
|
20 |
| -@JS() |
21 |
| -@staticInterop |
22 |
| -class Getter {} |
23 |
| - |
24 |
| -extension NamedExtension on Getter { |
25 |
| - external int get member; |
| 22 | +extension E2 on SameKindConflict { |
| 23 | + external String get getter; |
| 24 | + external set setter(int val); |
| 25 | + external String method(); |
26 | 26 | }
|
27 | 27 |
|
28 |
| -@JS() |
29 |
| -@staticInterop |
30 |
| -class Field {} |
31 |
| - |
32 |
| -extension on Field { |
33 |
| - external final String member; |
34 |
| -} |
35 |
| - |
36 |
| -@JS() |
37 |
| -@staticInterop |
38 |
| -class ExtendsImplementsConflict extends Method implements Getter {} |
39 |
| - |
40 |
| -@JS() |
41 |
| -@staticInterop |
42 |
| -class ImplementsConflict implements Method, Getter {} |
43 |
| - |
44 |
| -@JS() |
45 |
| -@staticInterop |
46 |
| -class ManyConflicts extends Method implements Getter, Field {} |
47 |
| - |
48 |
| -@JS() |
49 |
| -@staticInterop |
50 |
| -class Override implements Method {} |
51 |
| - |
52 |
| -extension on Override { |
53 |
| - external int member(); |
| 28 | +@JSExport() |
| 29 | +class DartSameKindConflict { |
| 30 | + String getter = ''; |
| 31 | + set setter(int val) => throw ''; |
| 32 | + String method() => throw ''; |
54 | 33 | }
|
55 | 34 |
|
56 |
| -@JS() |
57 |
| -@staticInterop |
58 |
| -class OverrideOneConflictButNotAll implements Override, Getter {} |
59 |
| - |
60 |
| -@JS() |
61 |
| -@staticInterop |
62 |
| -class ConflictThroughInheritance implements OverrideOneConflictButNotAll {} |
63 |
| - |
64 |
| -@JS() |
65 |
| -@staticInterop |
66 |
| -class ResolveThroughOverride implements ConflictThroughInheritance {} |
67 |
| - |
68 |
| -extension on ResolveThroughOverride { |
69 |
| - external int member; |
| 35 | +@JSExport() |
| 36 | +class IncorrectDartSameKindConflict { |
| 37 | + bool getter = true; |
| 38 | + set setter(bool val) => throw ''; |
| 39 | + bool method() => throw ''; |
70 | 40 | }
|
71 | 41 |
|
72 |
| -class ResolveThroughOverrideDart { |
73 |
| - int member = throw ''; |
| 42 | +void testSameKindConflict() { |
| 43 | + // No error as one of the extension members are implemented for each export |
| 44 | + // name. |
| 45 | + createStaticInteropMock<SameKindConflict, DartSameKindConflict>( |
| 46 | + DartSameKindConflict()); |
| 47 | + // Error as none of them are implemented for each export name. |
| 48 | + createStaticInteropMock<SameKindConflict, IncorrectDartSameKindConflict>( |
| 49 | +//^ |
| 50 | +// [web] Dart class 'IncorrectDartSameKindConflict' does not have any members that implement any of the following extension member(s) with export name 'getter': E1.getter (FunctionType(int Function())), E2.getter (FunctionType(String Function())). |
| 51 | +// [web] Dart class 'IncorrectDartSameKindConflict' does not have any members that implement any of the following extension member(s) with export name 'method': E1.method (FunctionType(int Function())), E2.method (FunctionType(String Function())). |
| 52 | +// [web] Dart class 'IncorrectDartSameKindConflict' does not have any members that implement any of the following extension member(s) with export name 'setter': E1.setter= (FunctionType(void Function(int))), E2.setter= (FunctionType(void Function(int))). |
| 53 | + IncorrectDartSameKindConflict()); |
74 | 54 | }
|
75 | 55 |
|
76 | 56 | @JS()
|
77 | 57 | @staticInterop
|
78 |
| -class Setter {} |
| 58 | +class DifferentKindConflict {} |
79 | 59 |
|
80 |
| -extension on Setter { |
81 |
| - external set member(int val); |
| 60 | +extension E3 on DifferentKindConflict { |
| 61 | + external int getSet; |
| 62 | + @JS('getSet') |
| 63 | + external void method(); |
82 | 64 | }
|
83 | 65 |
|
84 |
| -@JS() |
85 |
| -@staticInterop |
86 |
| -class NoConflictDueToSubtype implements Override, Method {} |
87 |
| - |
88 |
| -class NoConflictDueToSubtypeDart { |
89 |
| - int member() => throw ''; |
| 66 | +@JSExport() |
| 67 | +class ImplementGetter { |
| 68 | + int get getSet => throw ''; |
90 | 69 | }
|
91 | 70 |
|
92 |
| -@JS() |
93 |
| -@staticInterop |
94 |
| -class GetterSetterConflict implements Setter, Getter {} |
95 |
| - |
96 |
| -@JS() |
97 |
| -@staticInterop |
98 |
| -class GetterSetterSameExtension {} |
99 |
| - |
100 |
| -extension on GetterSetterSameExtension { |
101 |
| - external int get member; |
102 |
| - external set member(int val); |
| 71 | +@JSExport() |
| 72 | +class ImplementSetter { |
| 73 | + set getSet(int val) => throw ''; |
103 | 74 | }
|
104 | 75 |
|
105 |
| -class GetterSetterSameExtensionDart extends ResolveThroughOverrideDart {} |
106 |
| - |
107 |
| -@JS() |
108 |
| -@staticInterop |
109 |
| -class GetterSetterMethodConflict implements GetterSetterSameExtension, Method {} |
110 |
| - |
111 |
| -@JS() |
112 |
| -@staticInterop |
113 |
| -class NonExternal {} |
114 |
| - |
115 |
| -extension on NonExternal { |
116 |
| - int get member => throw ''; |
| 76 | +@JSExport() |
| 77 | +class ImplementBoth { |
| 78 | + int getSet = 0; |
117 | 79 | }
|
118 | 80 |
|
119 |
| -@JS() |
120 |
| -@staticInterop |
121 |
| -class ExternalNonExternal implements NonExternal, GetterSetterSameExtension {} |
122 |
| - |
123 |
| -class ExternalNonExternalDart extends ResolveThroughOverrideDart {} |
124 |
| - |
125 |
| -void main() { |
126 |
| - // Test name conflicts between extended and implemented members. |
127 |
| - createStaticInteropMock<ExtendsImplementsConflict, EmptyDart>( |
128 |
| -//^ |
129 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Getter.NamedExtension', 'Method.unnamed'. |
130 |
| - EmptyDart()); |
131 |
| - // Test name conflicts between implemented members. |
132 |
| - createStaticInteropMock<ImplementsConflict, EmptyDart>(EmptyDart()); |
133 |
| -//^ |
134 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Getter.NamedExtension', 'Method.unnamed'. |
135 |
| - |
136 |
| - // Test multiple name conflicts. |
137 |
| - createStaticInteropMock<ManyConflicts, EmptyDart>(EmptyDart()); |
138 |
| -//^ |
139 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Field.unnamed', 'Getter.NamedExtension', 'Method.unnamed'. |
| 81 | +@JSExport() |
| 82 | +class ImplementMethod { |
| 83 | + void getSet() {} |
| 84 | +} |
140 | 85 |
|
141 |
| - // Test name conflicts where one definition is overridden, but there is still |
142 |
| - // a name conflict between the other two. |
143 |
| - createStaticInteropMock<OverrideOneConflictButNotAll, EmptyDart>( |
144 |
| -//^ |
145 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Getter.NamedExtension', 'Override.unnamed'. |
146 |
| - EmptyDart()); |
147 |
| - // Test case where if we inherit a class with a conflict, the conflict still |
148 |
| - // exists. |
149 |
| - createStaticInteropMock<ConflictThroughInheritance, EmptyDart>( |
| 86 | +void testDifferentKindConflict() { |
| 87 | + // Missing setter error. |
| 88 | + createStaticInteropMock<DifferentKindConflict, ImplementGetter>( |
150 | 89 | //^
|
151 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Getter.NamedExtension', 'Override.unnamed'. |
152 |
| - EmptyDart()); |
153 |
| - // Test case where name conflicts are resolved using derived class. |
154 |
| - createStaticInteropMock<ResolveThroughOverride, ResolveThroughOverrideDart>( |
155 |
| - ResolveThroughOverrideDart()); |
156 |
| - // Test case where you inherit two classes with the same member name but they |
157 |
| - // have a subtype relation, so there is no conflict. |
158 |
| - createStaticInteropMock<NoConflictDueToSubtype, NoConflictDueToSubtypeDart>( |
159 |
| - NoConflictDueToSubtypeDart()); |
160 |
| - // Test conflict where getter and setter collide when they are in different |
161 |
| - // extensions. |
162 |
| - createStaticInteropMock<GetterSetterConflict, EmptyDart>(EmptyDart()); |
| 90 | +// [web] Dart class 'ImplementGetter' has a getter, but does not have a setter to implement any of the following extension member(s) with export name 'getSet': E3.getSet= (FunctionType(void Function(int))). |
| 91 | + ImplementGetter()); |
| 92 | + // Missing getter error. |
| 93 | + createStaticInteropMock<DifferentKindConflict, ImplementSetter>( |
163 | 94 | //^
|
164 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'Getter.NamedExtension', 'Setter.unnamed'. |
165 |
| - |
166 |
| - // Test no conflict where getter and setter are on the same extension. |
167 |
| - createStaticInteropMock<GetterSetterSameExtension, |
168 |
| - GetterSetterSameExtensionDart>(GetterSetterSameExtensionDart()); |
169 |
| - // Test conflict where getter and setter are in one extension, but there is |
170 |
| - // a conflict with another extension. |
171 |
| - createStaticInteropMock<GetterSetterMethodConflict, EmptyDart>(EmptyDart()); |
172 |
| -//^ |
173 |
| -// [web] External extension member with name 'member' is defined in the following extensions and none are more specific: 'GetterSetterSameExtension.unnamed', 'Method.unnamed'. |
174 |
| - |
175 |
| - // Test no conflict between external and non-external members. |
176 |
| - createStaticInteropMock<ExternalNonExternal, ExternalNonExternalDart>( |
177 |
| - ExternalNonExternalDart()); |
| 95 | +// [web] Dart class 'ImplementSetter' has a setter, but does not have a getter to implement any of the following extension member(s) with export name 'getSet': E3.getSet (FunctionType(int Function())). |
| 96 | + ImplementSetter()); |
| 97 | + // No error as both getter and setter are there, and we've satisfied an export |
| 98 | + // for `getSet`. |
| 99 | + createStaticInteropMock<DifferentKindConflict, ImplementBoth>( |
| 100 | + ImplementBoth()); |
| 101 | + // No error as we've satisfied an export for `getSet`. |
| 102 | + createStaticInteropMock<DifferentKindConflict, ImplementMethod>( |
| 103 | + ImplementMethod()); |
178 | 104 | }
|
0 commit comments