@@ -146,6 +146,13 @@ impl<'a> Compiler<'a> {
146146 name : "self" . to_string ( ) ,
147147 } ,
148148 ) ;
149+ // Method type parameters are passed as additional Class arguments
150+ for typaram in & signature. typarams {
151+ params. push ( mir:: Param {
152+ ty : mir:: Ty :: raw ( "Class" ) ,
153+ name : typaram. name . clone ( ) ,
154+ } ) ;
155+ }
149156 // Pass 1: collect cell vars before converting body
150157 self . lambda . cell_vars = if let SkMethodBody :: Normal { exprs } = & method. body {
151158 lambda:: collect_cell_vars ( exprs)
@@ -321,9 +328,12 @@ impl<'a> Compiler<'a> {
321328 }
322329 HirExpressionBase :: HirMethodTVarRef {
323330 typaram_ref,
324- n_params : _ ,
331+ n_params,
325332 } => {
326- todo ! ( "Handle method tvar ref: {:?}" , typaram_ref)
333+ // Method type parameters are passed as additional Class
334+ // arguments after self and explicit params.
335+ let idx = 1 + n_params + typaram_ref. idx ;
336+ mir:: Expr :: arg_ref ( idx, typaram_ref. name . clone ( ) , mir:: Ty :: raw ( "Class" ) )
327337 }
328338 HirExpressionBase :: HirLVarDecl {
329339 name,
@@ -374,6 +384,7 @@ impl<'a> Compiler<'a> {
374384 receiver_expr,
375385 method_fullname,
376386 arg_exprs,
387+ tyarg_exprs,
377388 is_virtual,
378389 ..
379390 } => {
@@ -387,6 +398,9 @@ impl<'a> Compiler<'a> {
387398 . map ( |e| e. ty . clone ( ) . into ( ) )
388399 . collect :: < Vec < _ > > ( ) ;
389400 param_tys. insert ( 0 , convert_ty ( method_fullname. type_name . to_ty ( ) ) ) ;
401+ for _ in & tyarg_exprs {
402+ param_tys. push ( mir:: Ty :: raw ( "Class" ) ) ;
403+ }
390404 mir:: FunTy :: new ( mir:: Asyncness :: Unknown , param_tys, expr. ty . clone ( ) . into ( ) )
391405 } ;
392406
@@ -423,6 +437,12 @@ impl<'a> Compiler<'a> {
423437 mir_receiver
424438 } ;
425439 mir_args. insert ( 0 , receiver_for_call) ;
440+ for tyarg in tyarg_exprs {
441+ let mir_tyarg = self . convert_expr ( tyarg) ;
442+ let casted =
443+ mir:: Expr :: cast ( mir:: CastType :: Force ( mir:: Ty :: raw ( "Class" ) ) , mir_tyarg) ;
444+ mir_args. push ( casted) ;
445+ }
426446
427447 ( mir:: Expr :: FunCall ( Box :: new ( func_ref) , mir_args) , result_ty)
428448 }
@@ -432,6 +452,7 @@ impl<'a> Compiler<'a> {
432452 method_name,
433453 method_idx,
434454 arg_exprs,
455+ tyarg_exprs,
435456 ..
436457 } => {
437458 let receiver_ty = receiver_expr. ty . clone ( ) ;
@@ -444,6 +465,9 @@ impl<'a> Compiler<'a> {
444465 . map ( |e| e. ty . clone ( ) . into ( ) )
445466 . collect :: < Vec < _ > > ( ) ;
446467 param_tys. insert ( 0 , convert_ty ( receiver_ty) ) ;
468+ for _ in & tyarg_exprs {
469+ param_tys. push ( mir:: Ty :: raw ( "Class" ) ) ;
470+ }
447471 mir:: FunTy :: new ( mir:: Asyncness :: Unknown , param_tys, expr. ty . clone ( ) . into ( ) )
448472 } ;
449473
@@ -461,6 +485,12 @@ impl<'a> Compiler<'a> {
461485 . map ( |arg| self . convert_expr ( arg) )
462486 . collect ( ) ;
463487 mir_args. insert ( 0 , mir_receiver) ;
488+ for tyarg in tyarg_exprs {
489+ let mir_tyarg = self . convert_expr ( tyarg) ;
490+ let casted =
491+ mir:: Expr :: cast ( mir:: CastType :: Force ( mir:: Ty :: raw ( "Class" ) ) , mir_tyarg) ;
492+ mir_args. push ( casted) ;
493+ }
464494
465495 let result_ty = convert_ty ( expr. ty . clone ( ) ) ;
466496 ( mir:: Expr :: FunCall ( Box :: new ( func_ref) , mir_args) , result_ty)
@@ -833,6 +863,10 @@ fn build_fun_ty(sig: &MethodSignature) -> mir::FunTy {
833863 . map ( |x| convert_ty ( x. ty . clone ( ) ) )
834864 . collect :: < Vec < _ > > ( ) ;
835865 param_tys. insert ( 0 , convert_ty ( sig. fullname . type_name . to_ty ( ) ) ) ;
866+ // Method type parameters are passed as additional Class arguments.
867+ for _ in & sig. typarams {
868+ param_tys. push ( mir:: Ty :: raw ( "Class" ) ) ;
869+ }
836870 mir:: FunTy :: new (
837871 sig. asyncness . clone ( ) . into ( ) ,
838872 param_tys,
0 commit comments