@@ -1042,14 +1042,32 @@ impl Compiler<'_> {
10421042 ) ) ) ;
10431043 } ;
10441044 let name_string = name. id . to_string ( ) ;
1045- if type_params. is_some ( ) {
1046- self . push_symbol_table ( ) ;
1047- }
1048- self . compile_expression ( value) ?;
1045+
1046+ // For PEP 695 syntax, we need to compile type_params first
1047+ // so that they're available when compiling the value expression
10491048 if let Some ( type_params) = type_params {
1049+ self . push_symbol_table ( ) ;
1050+
1051+ // Compile type params first to define T1, T2, etc.
10501052 self . compile_type_params ( type_params) ?;
1053+ // Stack now has type_params tuple at top
1054+
1055+ // Compile value expression (can now see T1, T2)
1056+ self . compile_expression ( value) ?;
1057+ // Stack: [type_params_tuple, value]
1058+
1059+ // We need [value, type_params_tuple] for TypeAlias instruction
1060+ emit ! ( self , Instruction :: Rotate2 ) ;
1061+
10511062 self . pop_symbol_table ( ) ;
1063+ } else {
1064+ // No type params - push value first, then None (not empty tuple)
1065+ self . compile_expression ( value) ?;
1066+ // Push None for type_params (matching CPython)
1067+ self . emit_load_const ( ConstantData :: None ) ;
10521068 }
1069+
1070+ // Push name last
10531071 self . emit_load_const ( ConstantData :: Str {
10541072 value : name_string. clone ( ) . into ( ) ,
10551073 } ) ;
0 commit comments