Skip to content

Commit b463c33

Browse files
committed
ngc: fix stack inconsistency bug when calling void methods from the reduced if body.
1 parent 29eff24 commit b463c33

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ngc/FormGenerator.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

135135
type 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

152156
type FullIfGenerator(context:Context,typeBuilder:TypeBuilder,condition:SExp,if_true:SExp,if_false:SExp,gf:IGeneratorFactory) =
153157
interface IGenerator with

0 commit comments

Comments
 (0)