-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support REPL softscope for Julia 1.5. (#1232)
Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
- Loading branch information
1 parent
df096fc
commit 18722b7
Showing
10 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
REPL scoping behaviour when Julia < 1.5 | ||
|
||
```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)+" | ||
julia> s = 0 # global | ||
0 | ||
julia> for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # assign global `s` | ||
end | ||
ERROR: UndefVarError: s not defined | ||
Stacktrace: | ||
[1] top-level scope at ./none:2 | ||
[...] | ||
``` | ||
|
||
```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)+" | ||
julia> code = """ | ||
s = 0 # global | ||
for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # new local `s` with warning | ||
end | ||
s, # global | ||
@isdefined(t) # global | ||
"""; | ||
julia> include_string(Main, code) | ||
ERROR: LoadError: UndefVarError: s not defined | ||
Stacktrace: | ||
[1] top-level scope at ./string:3 | ||
[2] include_string(::Module, ::String, ::String) at ./loading.jl:1075 | ||
[...] | ||
``` | ||
|
||
```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)+" | ||
s = 0 # global | ||
for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # new local `s` with warning | ||
end | ||
s, # global | ||
@isdefined(t) # global | ||
# output | ||
ERROR: UndefVarError: s not defined | ||
Stacktrace: | ||
[1] top-level scope at ./none:2 | ||
[...] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Julia 1.5's REPL softscope | ||
|
||
```jldoctest | ||
julia> s = 0 # global | ||
0 | ||
julia> for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # assign global `s` | ||
end | ||
julia> s # global | ||
55 | ||
julia> @isdefined(t) # global | ||
false | ||
``` | ||
|
||
```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" | ||
julia> code = """ | ||
s = 0 # global | ||
for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # new local `s` with warning | ||
end | ||
s, # global | ||
@isdefined(t) # global | ||
"""; | ||
julia> include_string(Main, code) | ||
┌ Warning: Assignment to `s` in soft scope is ambiguous because a global variable by the same name exists: `s` will be treated as a new local. Disambiguate by using `local s` to suppress this warning or `global s` to assign to the existing global variable. | ||
└ @ string:4 | ||
ERROR: LoadError: UndefVarError: s not defined | ||
Stacktrace: | ||
[1] top-level scope at ./string:3 | ||
[2] include_string(::Module, ::String, ::String) at ./loading.jl:1080 | ||
[...] | ||
``` | ||
|
||
```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*" | ||
s = 0 # global | ||
for i = 1:10 | ||
t = s + i # new local `t` | ||
s = t # new local `s` with warning | ||
end | ||
s, # global | ||
@isdefined(t) # global | ||
# output | ||
┌ Warning: Assignment to `s` in soft scope is ambiguous because a global variable by the same name exists: `s` will be treated as a new local. Disambiguate by using `local s` to suppress this warning or `global s` to assign to the existing global variable. | ||
└ @ none:3 | ||
ERROR: UndefVarError: s not defined | ||
Stacktrace: | ||
[1] top-level scope at ./none:2 | ||
[...] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ Info: SetupBuildDirectory: setting up build directory. | ||
[ Info: Doctest: running doctests. | ||
[ Info: ExpandTemplates: expanding markdown templates. | ||
[ Info: CrossReferences: building cross-references. | ||
[ Info: CheckDocument: running document checks. | ||
[ Info: Populate: populating indices. | ||
[ Info: RenderDocument: rendering document. | ||
[ Info: HTMLWriter: rendering HTML pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ Info: SetupBuildDirectory: setting up build directory. | ||
[ Info: Doctest: running doctests. | ||
[ Info: ExpandTemplates: expanding markdown templates. | ||
[ Info: CrossReferences: building cross-references. | ||
[ Info: CheckDocument: running document checks. | ||
[ Info: Populate: populating indices. | ||
[ Info: RenderDocument: rendering document. | ||
[ Info: HTMLWriter: rendering HTML pages. |