@@ -182,43 +182,36 @@ pub fn typecheck_value_against_schematype(
182
182
/// Check whether the given `RestrictedExpr` is a valid instance of `SchemaType`
183
183
pub fn does_restricted_expr_implement_schematype (
184
184
expr : BorrowedRestrictedExpr < ' _ > ,
185
- expr_ty : & SchemaType ,
186
185
expected_ty : & SchemaType ,
187
186
extensions : & Extensions < ' _ > ,
188
187
) -> bool {
189
188
use SchemaType :: * ;
190
- if expr_ty == expected_ty {
191
- return true ;
192
- }
193
189
194
- match ( expr_ty, expected_ty) {
195
- ( Set { .. } , EmptySet ) => true ,
196
- ( EmptySet , Set { .. } ) => true ,
197
- (
198
- Set {
199
- element_ty : expr_elm_ty,
200
- } ,
201
- Set { element_ty : elty } ,
202
- ) => match expr. as_set_elements ( ) {
203
- Some ( mut els) => els. all ( |e| {
204
- does_restricted_expr_implement_schematype ( e, expr_elm_ty, elty, extensions)
205
- } ) ,
190
+ match expected_ty {
191
+ Bool => expr. as_bool ( ) . is_some ( ) ,
192
+ Long => expr. as_long ( ) . is_some ( ) ,
193
+ String => expr. as_string ( ) . is_some ( ) ,
194
+ EmptySet => expr. as_set_elements ( ) . is_some ( ) ,
195
+ Set { .. }
196
+ if expr. as_set_elements ( ) . is_some ( ) && expr. as_set_elements ( ) . unwrap ( ) . count ( ) == 0 =>
197
+ {
198
+ true
199
+ }
200
+
201
+ Set { element_ty : elty } => match expr. as_set_elements ( ) {
202
+ Some ( mut els) => {
203
+ els. all ( |e| does_restricted_expr_implement_schematype ( e, elty, extensions) )
204
+ }
206
205
None => false ,
207
206
} ,
208
- (
209
- Record {
210
- attrs : expr_attrs, ..
211
- } ,
212
- Record { attrs, open_attrs } ,
213
- ) => match expr. as_record_pairs ( ) {
207
+ Record { attrs, open_attrs } => match expr. as_record_pairs ( ) {
214
208
Some ( pairs) => {
215
209
let pairs_map: BTreeMap < & SmolStr , BorrowedRestrictedExpr < ' _ > > = pairs. collect ( ) ;
216
210
let all_req_schema_attrs_in_record = attrs. iter ( ) . all ( |( k, v) | {
217
211
!v. required
218
212
|| match pairs_map. get ( k) {
219
213
Some ( inner_e) => does_restricted_expr_implement_schematype (
220
214
* inner_e,
221
- & expr_attrs. get ( k) . unwrap ( ) . attr_type ,
222
215
& v. attr_type ,
223
216
extensions,
224
217
) ,
@@ -229,7 +222,6 @@ pub fn does_restricted_expr_implement_schematype(
229
222
pairs_map. iter ( ) . all ( |( k, inner_e) | match attrs. get ( * k) {
230
223
Some ( sch_ty) => does_restricted_expr_implement_schematype (
231
224
* inner_e,
232
- & expr_attrs. get ( * k) . unwrap ( ) . attr_type ,
233
225
& sch_ty. attr_type ,
234
226
extensions,
235
227
) ,
@@ -239,7 +231,17 @@ pub fn does_restricted_expr_implement_schematype(
239
231
}
240
232
None => false ,
241
233
} ,
242
- _ => false ,
234
+ Extension { name } => match expr. as_extn_fn_call ( ) {
235
+ Some ( ( actual_name, _) ) => match format ! ( "{:?}" , name. 0 . id) . as_str ( ) {
236
+ "Id(\" ipaddr\" )" => format ! ( "{:?}" , actual_name. 0 . id) . as_str ( ) == "Id(\" ip\" )" ,
237
+ _ => name == actual_name,
238
+ } ,
239
+ None => false ,
240
+ } ,
241
+ Entity { ty } => match expr. as_euid ( ) {
242
+ Some ( actual_euid) => actual_euid. entity_type ( ) == ty,
243
+ None => false ,
244
+ } ,
243
245
}
244
246
}
245
247
@@ -257,8 +259,7 @@ pub fn typecheck_restricted_expr_against_schematype(
257
259
// directly?
258
260
match schematype_of_restricted_expr ( expr, extensions) {
259
261
Ok ( actual_ty) => {
260
- if does_restricted_expr_implement_schematype ( expr, & actual_ty, expected_ty, extensions)
261
- {
262
+ if does_restricted_expr_implement_schematype ( expr, expected_ty, extensions) {
262
263
// typecheck passes
263
264
Ok ( ( ) )
264
265
} else {
0 commit comments