@@ -8563,7 +8563,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8563
8563
8564
8564
fn infer_subscript_expression_types (
8565
8565
& self ,
8566
- value_node : & ast:: Expr ,
8566
+ value_node : & ' ast ast:: Expr ,
8567
8567
value_ty : Type < ' db > ,
8568
8568
slice_ty : Type < ' db > ,
8569
8569
expr_context : ExprContext ,
@@ -8732,7 +8732,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8732
8732
. map ( |context| {
8733
8733
Type :: KnownInstance ( KnownInstanceType :: SubscriptedProtocol ( context) )
8734
8734
} )
8735
- . unwrap_or_else ( Type :: unknown ) ,
8735
+ . unwrap_or_else ( GenericContextError :: into_type ) ,
8736
8736
// TODO: emit a diagnostic
8737
8737
TupleSpec :: Variable ( _) => Type :: unknown ( ) ,
8738
8738
} )
@@ -8745,7 +8745,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8745
8745
LegacyGenericBase :: Protocol ,
8746
8746
)
8747
8747
. map ( |context| Type :: KnownInstance ( KnownInstanceType :: SubscriptedProtocol ( context) ) )
8748
- . unwrap_or_else ( Type :: unknown ) ,
8748
+ . unwrap_or_else ( GenericContextError :: into_type ) ,
8749
8749
) ,
8750
8750
8751
8751
( Type :: KnownInstance ( KnownInstanceType :: SubscriptedProtocol ( _) ) , _) => {
@@ -8764,7 +8764,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8764
8764
. map ( |context| {
8765
8765
Type :: KnownInstance ( KnownInstanceType :: SubscriptedGeneric ( context) )
8766
8766
} )
8767
- . unwrap_or_else ( Type :: unknown ) ,
8767
+ . unwrap_or_else ( GenericContextError :: into_type ) ,
8768
8768
// TODO: emit a diagnostic
8769
8769
TupleSpec :: Variable ( _) => Type :: unknown ( ) ,
8770
8770
} )
@@ -8777,7 +8777,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8777
8777
LegacyGenericBase :: Generic ,
8778
8778
)
8779
8779
. map ( |context| Type :: KnownInstance ( KnownInstanceType :: SubscriptedGeneric ( context) ) )
8780
- . unwrap_or_else ( Type :: unknown ) ,
8780
+ . unwrap_or_else ( GenericContextError :: into_type ) ,
8781
8781
) ,
8782
8782
8783
8783
( Type :: KnownInstance ( KnownInstanceType :: SubscriptedGeneric ( _) ) , _) => {
@@ -8946,11 +8946,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8946
8946
value_node : & ast:: Expr ,
8947
8947
typevars : & [ Type < ' db > ] ,
8948
8948
origin : LegacyGenericBase ,
8949
- ) -> Option < GenericContext < ' db > > {
8950
- let typevars: Option < FxOrderSet < _ > > = typevars
8949
+ ) -> Result < GenericContext < ' db > , GenericContextError > {
8950
+ let typevars: Result < FxOrderSet < _ > , GenericContextError > = typevars
8951
8951
. iter ( )
8952
8952
. map ( |typevar| match typevar {
8953
- Type :: KnownInstance ( KnownInstanceType :: TypeVar ( typevar) ) => Some ( * typevar) ,
8953
+ Type :: KnownInstance ( KnownInstanceType :: TypeVar ( typevar) ) => Ok ( * typevar) ,
8954
+ Type :: NominalInstance ( NominalInstanceType { class, .. } )
8955
+ if matches ! (
8956
+ class. known( self . db( ) ) ,
8957
+ Some ( KnownClass :: TypeVarTuple | KnownClass :: ParamSpec )
8958
+ ) =>
8959
+ {
8960
+ Err ( GenericContextError :: NotYetSupported )
8961
+ }
8954
8962
_ => {
8955
8963
if let Some ( builder) =
8956
8964
self . context . report_lint ( & INVALID_ARGUMENT_TYPE , value_node)
@@ -8960,7 +8968,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
8960
8968
typevar. display( self . db( ) ) ,
8961
8969
) ) ;
8962
8970
}
8963
- None
8971
+ Err ( GenericContextError :: InvalidArgument )
8964
8972
}
8965
8973
} )
8966
8974
. collect ( ) ;
@@ -10860,6 +10868,24 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
10860
10868
}
10861
10869
}
10862
10870
10871
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
10872
+ enum GenericContextError {
10873
+ /// It's invalid to subscript `Generic` or `Protocol` with this type
10874
+ InvalidArgument ,
10875
+ /// It's valid to subscribe `Generic` or `Protocol` with this type,
10876
+ /// but the type is not yet supported.
10877
+ NotYetSupported ,
10878
+ }
10879
+
10880
+ impl GenericContextError {
10881
+ const fn into_type < ' db > ( self ) -> Type < ' db > {
10882
+ match self {
10883
+ GenericContextError :: InvalidArgument => Type :: unknown ( ) ,
10884
+ GenericContextError :: NotYetSupported => todo_type ! ( "ParamSpecs and TypeVarTuples" ) ,
10885
+ }
10886
+ }
10887
+ }
10888
+
10863
10889
/// The deferred state of a specific expression in an inference region.
10864
10890
#[ derive( Default , Debug , Clone , Copy ) ]
10865
10891
enum DeferredExpressionState {
0 commit comments