Okay all is good, I fixed it here by moving back to the closure approach:
function _stable(fex::Expr)
func = splitdef(fex)
...
@gensym closure T
func[:body] = quote
let $closure() = $(func[:body]), $T = $(Base).promote_op($closure)
if !$(Base).isconcretetype($T)
...
end
return $closure()::$T
end
end
return combinedef(func)
end
It seems like promote_op
gets the same results if you put all the function body in a closure. And, as before, the check looks to compile away if everything is type-stable.