@@ -143,6 +143,16 @@ namespace internal {
143
143
return const_cast <UnstableNode&>(element.feature );
144
144
}
145
145
146
+ inline
147
+ UnstableNode valueOf (VM vm, const UnstableNode& element) {
148
+ return UnstableNode ();
149
+ }
150
+
151
+ inline
152
+ UnstableNode& valueOf (VM vm, const UnstableField& element) {
153
+ return const_cast <UnstableNode&>(element.value );
154
+ }
155
+
146
156
template <class T >
147
157
inline
148
158
bool isTupleFeatureArray (VM vm, size_t width, T elements[]) {
@@ -155,17 +165,37 @@ namespace internal {
155
165
156
166
return true ;
157
167
}
158
- }
159
168
160
- template <class T >
161
- void sortFeatures (VM vm, size_t width, T features[]) {
162
- using internal::featureOf;
169
+ template <class T >
170
+ inline
171
+ void sortFeatures (VM vm, size_t width, T features[]) {
172
+ std::sort (features, features+width,
173
+ [vm] (const T& lhs, const T& rhs) -> bool {
174
+ return compareFeatures (vm, featureOf (lhs), featureOf (rhs)) < 0 ;
175
+ }
176
+ );
177
+ }
178
+
179
+ template <class T >
180
+ inline
181
+ bool findDuplicateFeature (VM vm, size_t width, T features[]) {
182
+ return features+width != std::adjacent_find (features, features+width,
183
+ [vm] (const T& lhs, const T& rhs) -> bool {
184
+ return !compareFeatures (vm, featureOf (lhs), featureOf (rhs));
185
+ }
186
+ );
187
+ }
188
+
189
+ template <class T >
190
+ inline
191
+ UnstableNode featuresList (VM vm, size_t width, T features[]) {
192
+ return buildListDynamic (vm, width, features,
193
+ [vm] (const T& e) -> UnstableNode {
194
+ return buildSharp (vm, featureOf (e), valueOf (vm, e));
195
+ }
196
+ );
197
+ }
163
198
164
- std::sort (features, features+width,
165
- [vm] (const T& lhs, const T& rhs) -> bool {
166
- return compareFeatures (vm, featureOf (lhs), featureOf (rhs)) < 0 ;
167
- }
168
- );
169
199
}
170
200
171
201
template <class T >
@@ -181,7 +211,12 @@ UnstableNode buildArityDynamic(VM vm, RichNode label, size_t width,
181
211
requireFeature (vm, featureOf (elements[i]));
182
212
183
213
// Sort the features
184
- sortFeatures (vm, width, elements);
214
+ internal::sortFeatures (vm, width, elements);
215
+
216
+ // Forbid duplicated features
217
+ if (internal::findDuplicateFeature (vm, width, elements))
218
+ raiseKernelError (vm, " recordConstruction" , label,
219
+ internal::featuresList (vm, width, elements));
185
220
186
221
// Check if the corresponding record should be a Tuple instead
187
222
if (internal::isTupleFeatureArray (vm, width, elements))
0 commit comments