@@ -250,6 +250,11 @@ impl TyCustomImpl for TyUser {
250250 }
251251
252252 fn intersects_with ( & self , other : & TyBasic ) -> bool {
253+ if let TyBasic :: StarlarkValue ( other) = other {
254+ if self . base == * other {
255+ return true ;
256+ }
257+ }
253258 self . supertypes . iter ( ) . any ( |x| x == other)
254259 }
255260}
@@ -353,8 +358,18 @@ mod tests {
353358 name : String ,
354359 }
355360
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+
356367 #[ 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+ }
358373
359374 #[ starlark_module]
360375 fn globals ( globals : & mut GlobalsBuilder ) {
@@ -390,11 +405,15 @@ mod tests {
390405 } )
391406 }
392407
408+ fn mk_fruit ( ) -> anyhow:: Result < Fruit > {
409+ panic ! ( "not needed in test" )
410+ }
411+
393412 const Plant : StarlarkValueAsType < AbstractPlant > = StarlarkValueAsType :: new ( ) ;
394413 }
395414
396415 #[ test]
397- fn test_intersect ( ) {
416+ fn test_intersect_with_abstract_type ( ) {
398417 let mut a = Assert :: new ( ) ;
399418 a. globals_add ( globals) ;
400419 a. pass (
@@ -406,6 +425,26 @@ def make_apple() -> Apple:
406425
407426def make_plant() -> Plant:
408427 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())
409448"# ,
410449 ) ;
411450 }
0 commit comments