@@ -66,7 +66,7 @@ type BodyGenerator(context : Context,
6666 ilGen.Emit( OpCodes.Ldnull)
6767 | [ last] ->
6868 let gen = gf.MakeGenerator context last
69- let stackType = Seq .head <| gen.ReturnTypes ()
69+ let stackType = List .head <| gen.ReturnTypes ()
7070 let returnType = methodBuilder.ReturnType
7171 gen.Generate ilGen
7272 match ( stackType, returnType) with
@@ -133,6 +133,7 @@ type LetGenerator(context : Context,
133133 ( gf.MakeBody type_ subctx body) .ReturnTypes()
134134
135135type ReducedIfGenerator ( context : Context , typeBuilder : TypeBuilder , condition : SExp , if_true : SExp , gf : IGeneratorFactory ) =
136+ let returnTypes = ( gf.MakeGenerator context if_ true) .ReturnTypes()
136137 interface IGenerator with
137138 member this.Generate ilGen =
138139 let cond_gen = gf.MakeGenerator context condition
@@ -141,13 +142,16 @@ type ReducedIfGenerator(context:Context,typeBuilder:TypeBuilder,condition:SExp,i
141142 let end_form = ilGen.DefineLabel()
142143 cond_ gen.Generate ilGen
143144 ilGen.Emit ( OpCodes.Brtrue, if_ true_ lbl)
144- ilGen.Emit OpCodes.Ldnull
145- ilGen.Emit ( OpCodes.Br, end_ form)
145+
146+ if List.head returnTypes <> typeof< Void>
147+ then ilGen.Emit OpCodes.Ldnull
148+
149+ ilGen.Emit ( OpCodes.Br, end_ form)
146150 ilGen.MarkLabel if_ true_ lbl
147151 if_ true_ gen.Generate ilGen
148152 ilGen.MarkLabel end_ form
149153 member this.ReturnTypes () =
150- ( gf.MakeGenerator context if _ true ) .ReturnTypes ()
154+ returnTypes
151155
152156type FullIfGenerator ( context : Context , typeBuilder : TypeBuilder , condition : SExp , if_true : SExp , if_false : SExp , gf : IGeneratorFactory ) =
153157 interface IGenerator with
0 commit comments