Commit 57c50f1
committed
Fixed a bug in replace returns (#352)
On master we have the following behavior for a test-case in Turing.jl:
```julia
julia> @macroexpand @model empty_model() = begin x = 1; end
quote
function empty_model(__model__::DynamicPPL.Model, __varinfo__::DynamicPPL.AbstractVarInfo, __context__::DynamicPPL.AbstractContext; )
#= REPL[5]:1 =#
begin
#= REPL[5]:1 =#
#= REPL[5]:1 =#
return (x = 1, __varinfo__)
end
end
begin
$(Expr(:meta, :doc))
function empty_model(; )
#= REPL[5]:1 =#
return (DynamicPPL.Model)(:empty_model, empty_model, NamedTuple(), NamedTuple())
end
end
end
```
Notice the `return` statement: it converted the statement `x = 1` which returns `1` into an attempt at a `NamedTuple{(:x, :__varinfo__)}`. On Julia 1.6 we don't really notice much of difference, because `first` and `last` will have the same behavior, but on Julia 1.3 the tests would fail in TuringLang/Turing.jl#1726 since "implicit" names in construction of `NamedTuple` isn't supported.
This PR addresses this issue by simply capturing the return-value in separate variable, which is then combined with `__varinfo__` in a `Tuple` at the end. This should both fail and succeed whenever standard Julia code would.1 parent 28c6004 commit 57c50f1
3 files changed
+18
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
528 | 531 | | |
529 | | - | |
530 | | - | |
531 | 532 | | |
532 | 533 | | |
533 | 534 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
549 | 556 | | |
550 | 557 | | |
551 | 558 | | |
| |||
0 commit comments