@@ -250,6 +250,11 @@ impl TyCustomImpl for TyUser {
250
250
}
251
251
252
252
fn intersects_with ( & self , other : & TyBasic ) -> bool {
253
+ if let TyBasic :: StarlarkValue ( other) = other {
254
+ if self . base == * other {
255
+ return true ;
256
+ }
257
+ }
253
258
self . supertypes . iter ( ) . any ( |x| x == other)
254
259
}
255
260
}
@@ -353,8 +358,18 @@ mod tests {
353
358
name : String ,
354
359
}
355
360
361
+ impl < ' v > AllocValue < ' v > for Fruit {
362
+ fn alloc_value ( self , _heap : & ' v Heap ) -> Value < ' v > {
363
+ unreachable ! ( "not needed in test" )
364
+ }
365
+ }
366
+
356
367
#[ starlark_value( type = "fruit" ) ]
357
- impl < ' v > StarlarkValue < ' v > for Fruit { }
368
+ impl < ' v > StarlarkValue < ' v > for Fruit {
369
+ fn get_type_starlark_repr ( ) -> Ty {
370
+ Ty :: starlark_value :: < Fruit > ( )
371
+ }
372
+ }
358
373
359
374
#[ starlark_module]
360
375
fn globals ( globals : & mut GlobalsBuilder ) {
@@ -390,11 +405,15 @@ mod tests {
390
405
} )
391
406
}
392
407
408
+ fn mk_fruit ( ) -> anyhow:: Result < Fruit > {
409
+ panic ! ( "not needed in test" )
410
+ }
411
+
393
412
const Plant : StarlarkValueAsType < AbstractPlant > = StarlarkValueAsType :: new ( ) ;
394
413
}
395
414
396
415
#[ test]
397
- fn test_intersect ( ) {
416
+ fn test_intersect_with_abstract_type ( ) {
398
417
let mut a = Assert :: new ( ) ;
399
418
a. globals_add ( globals) ;
400
419
a. pass (
@@ -406,6 +425,26 @@ def make_apple() -> Apple:
406
425
407
426
def make_plant() -> Plant:
408
427
return make_apple()
428
+ "# ,
429
+ ) ;
430
+ }
431
+
432
+ #[ test]
433
+ fn test_ty_user_intersects_with_base_starlark_value ( ) {
434
+ let mut a = Assert :: new ( ) ;
435
+ a. globals_add ( globals) ;
436
+ a. pass (
437
+ r#"
438
+ Pear = fruit("pear")
439
+
440
+ def takes_pear(x: Pear):
441
+ pass
442
+
443
+ def test():
444
+ # `Pear` is `TyUser` with base `TyStarlarkValue::new::<Fruit>`.
445
+ # `mk_fruit()` is `TyStarlarkValue::new::<Fruit>()`.
446
+ # They should intersect.
447
+ takes_pear(mk_fruit())
409
448
"# ,
410
449
) ;
411
450
}
0 commit comments