@@ -103,8 +103,9 @@ templateEFilter = defineTypeParameterizedTemplate templateCreator path t docs
103103 _ -> declaration " ((($a*)a.data)[insertIndex++]) = (($a*)a.data)[i];" deleteCall
104104 )
105105 )
106- ( \ (FuncTy [RefTy ft@ (FuncTy fArgTys@ [RefTy _ _] BoolTy _) _, _] _ _) ->
106+ ( \ (FuncTy [RefTy ft@ (FuncTy fArgTys@ [RefTy insideType _] BoolTy _) _, _] _ _) ->
107107 [defineFunctionTypeAlias ft, defineFunctionTypeAlias (FuncTy (lambdaEnvTy : fArgTys) BoolTy StaticLifetimeTy )]
108+ ++ depsForDeleteFunc typeEnv env insideType
108109 )
109110
110111templatePushBack :: (String , Binder )
@@ -329,7 +330,9 @@ templateAset = defineTypeParameterizedTemplate templateCreator path t docs
329330 " }"
330331 ]
331332 )
332- (const [] )
333+ ( \ (FuncTy [_, _, insideTy] _ _) ->
334+ depsForDeleteFunc typeEnv env insideTy
335+ )
333336
334337templateAsetBang :: (String , Binder )
335338templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs
@@ -361,7 +364,9 @@ templateAsetBang = defineTypeParameterizedTemplate templateCreator path t docs
361364 " }"
362365 ]
363366 )
364- (const [] )
367+ ( \ (FuncTy [RefTy arrayType _, _, _] _ _) ->
368+ depsForDeleteFunc typeEnv env arrayType
369+ )
365370
366371-- | This function can set uninitialized memory in an array (used together with 'allocate').
367372-- | It will NOT try to free the value that is already at location 'n'.
@@ -402,12 +407,14 @@ templateLength = defineTypeParameterizedTemplate templateCreator path t docs
402407 t = FuncTy [RefTy (StructTy (ConcreteNameTy (SymPath [] " Array" )) [VarTy " t" ]) (VarTy " q" )] IntTy StaticLifetimeTy
403408 docs = " gets the length of the array."
404409 templateCreator = TemplateCreator $
405- \ _ _ ->
410+ \ typeEnv env ->
406411 Template
407412 t
408413 (const (toTemplate " int $NAME (Array *a)" ))
409414 (const (toTemplate " $DECL { return (*a).len; }" ))
410- (const [] )
415+ ( \ (FuncTy [RefTy arrayType _] _ _) ->
416+ depsForDeleteFunc typeEnv env arrayType
417+ )
411418
412419templateAllocate :: (String , Binder )
413420templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
@@ -416,7 +423,7 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
416423 t = FuncTy [IntTy ] (StructTy (ConcreteNameTy (SymPath [] " Array" )) [VarTy " t" ]) StaticLifetimeTy
417424 docs = " allocates an uninitialized array. You can initialize members using [`aset-uninitialized`](#aset-uninitialized)."
418425 templateCreator = TemplateCreator $
419- \ _ _ ->
426+ \ typeEnv env ->
420427 Template
421428 t
422429 (const (toTemplate " Array $NAME (int n)" ))
@@ -435,7 +442,9 @@ templateAllocate = defineTypeParameterizedTemplate templateCreator path t docs
435442 ]
436443 )
437444 )
438- (const [] )
445+ ( \ (FuncTy [_] arrayType _) ->
446+ depsForDeleteFunc typeEnv env arrayType
447+ )
439448
440449templateDeleteArray :: (String , Binder )
441450templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t docs
@@ -453,7 +462,9 @@ templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t doc
453462 ++ deleteTy typeEnv env arrayType
454463 ++ [TokC " }\n " ]
455464 )
456- (const [] )
465+ ( \ (FuncTy [StructTy (ConcreteNameTy (SymPath [] " Array" )) [insideType]] UnitTy _) ->
466+ depsForDeleteFunc typeEnv env insideType
467+ )
457468
458469deleteTy :: TypeEnv -> Env -> Ty -> [Token ]
459470deleteTy typeEnv env (StructTy _ [innerType]) =
0 commit comments