@@ -5785,8 +5785,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
57855785 //
57865786 // Infer all expressions with diagnostics enabled before starting multi-inference.
57875787 for item in items {
5788- self . infer_optional_expression ( item. key . as_ref ( ) , TypeContext :: default ( ) ) ;
5789- self . infer_expression ( & item. value , TypeContext :: default ( ) ) ;
5788+ if let Some ( key) = item. key . as_ref ( ) {
5789+ let key_ty = self . infer_expression ( key, TypeContext :: default ( ) ) ;
5790+ item_types. insert ( key. node_index ( ) . load ( ) , key_ty) ;
5791+ }
5792+
5793+ let value_ty = self . infer_expression ( & item. value , TypeContext :: default ( ) ) ;
5794+ item_types. insert ( item. value . node_index ( ) . load ( ) , value_ty) ;
57905795 }
57915796
57925797 // Disable diagnostics as we attempt to narrow to specific elements of the union.
@@ -5795,6 +5800,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
57955800 self . set_multi_inference_state ( MultiInferenceState :: Ignore ) ;
57965801
57975802 let mut narrowed_tys = Vec :: new ( ) ;
5803+ let mut item_types = FxHashMap :: default ( ) ;
57985804 for element in tcx. elements ( self . db ( ) ) {
57995805 let typed_dict = element
58005806 . as_typed_dict ( )
@@ -5835,8 +5841,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
58355841 // dictionary literal as a `TypedDict`. This also allows us to infer using the
58365842 // type context of the expected `TypedDict` field.
58375843 let mut infer_elt_ty = |builder : & mut Self , ( _, elt, tcx) : ArgExpr < ' db , ' _ > | {
5838- builder
5839- . try_expression_type ( elt)
5844+ item_types
5845+ . get ( & elt. node_index ( ) . load ( ) )
5846+ . copied ( )
58405847 . unwrap_or_else ( || builder. infer_expression ( elt, tcx) )
58415848 } ;
58425849
0 commit comments