Skip to content

Commit 03860b9

Browse files
committed
quote variable name in UndefVarError and UndefKeywordError
1 parent b9d539d commit 03860b9

12 files changed

+28
-28
lines changed

base/docs/basedocs.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ A symbol in the current scope is not defined.
17501750
# Examples
17511751
```jldoctest
17521752
julia> a
1753-
ERROR: UndefVarError: a not defined
1753+
ERROR: UndefVarError: `a` not defined
17541754
17551755
julia> a = 1;
17561756
@@ -1773,7 +1773,7 @@ julia> function my_func(;my_arg)
17731773
my_func (generic function with 1 method)
17741774
17751775
julia> my_func()
1776-
ERROR: UndefKeywordError: keyword argument my_arg not assigned
1776+
ERROR: UndefKeywordError: keyword argument `my_arg` not assigned
17771777
Stacktrace:
17781778
[1] my_func() at ./REPL[1]:2
17791779
[2] top-level scope at REPL[2]:1

base/errorshow.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ showerror(io::IO, ex::AssertionError) = print(io, "AssertionError: ", ex.msg)
157157
showerror(io::IO, ex::OverflowError) = print(io, "OverflowError: ", ex.msg)
158158

159159
showerror(io::IO, ex::UndefKeywordError) =
160-
print(io, "UndefKeywordError: keyword argument $(ex.var) not assigned")
160+
print(io, "UndefKeywordError: keyword argument `$(ex.var)` not assigned")
161161

162162
function showerror(io::IO, ex::UndefVarError)
163-
print(io, "UndefVarError: $(ex.var) not defined")
163+
print(io, "UndefVarError: `$(ex.var)` not defined")
164164
Experimental.show_error_hints(io, ex)
165165
end
166166

base/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ julia> Foo(b="hi")
522522
Foo(1, "hi")
523523
524524
julia> Foo()
525-
ERROR: UndefKeywordError: keyword argument b not assigned
525+
ERROR: UndefKeywordError: keyword argument `b` not assigned
526526
Stacktrace:
527527
[...]
528528
```

doc/src/manual/control-flow.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ julia> test(1,2)
139139
x is less than y.
140140
141141
julia> test(2,1)
142-
ERROR: UndefVarError: relation not defined
142+
ERROR: UndefVarError: `relation` not defined
143143
Stacktrace:
144144
[1] test(::Int64, ::Int64) at ./none:7
145145
```
@@ -433,7 +433,7 @@ julia> for j = 1:3
433433
3
434434
435435
julia> j
436-
ERROR: UndefVarError: j not defined
436+
ERROR: UndefVarError: `j` not defined
437437
```
438438

439439
```jldoctest

doc/src/manual/distributed-computing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ MyType(7)
209209
210210
julia> fetch(@spawnat 2 MyType(7))
211211
ERROR: On worker 2:
212-
UndefVarError: MyType not defined
212+
UndefVarError: `MyType` not defined
213213
214214
215215
julia> fetch(@spawnat 2 DummyModule.MyType(7))

doc/src/manual/faq.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ while x < 10
154154
end
155155
```
156156
and notice that it works fine in an interactive environment (like the Julia REPL),
157-
but gives `UndefVarError: x not defined` when you try to run it in script or other
157+
but gives ```UndefVarError: `x` not defined``` when you try to run it in script or other
158158
file. What is going on is that Julia generally requires you to **be explicit about assigning to global variables in a local scope**.
159159

160160
Here, `x` is a global variable, `while` defines a [local scope](@ref scope-of-variables), and `x += 1` is
@@ -705,7 +705,7 @@ julia> module Foo
705705
706706
julia> Foo.foo()
707707
ERROR: On worker 2:
708-
UndefVarError: Foo not defined
708+
UndefVarError: `Foo` not defined
709709
Stacktrace:
710710
[...]
711711
```
@@ -726,7 +726,7 @@ julia> @everywhere module Foo
726726
727727
julia> Foo.foo()
728728
ERROR: On worker 2:
729-
UndefVarError: gvar not defined
729+
UndefVarError: `gvar` not defined
730730
Stacktrace:
731731
[...]
732732
```
@@ -762,7 +762,7 @@ bar (generic function with 1 method)
762762
763763
julia> remotecall_fetch(bar, 2)
764764
ERROR: On worker 2:
765-
UndefVarError: #bar not defined
765+
UndefVarError: `#bar` not defined
766766
[...]
767767
768768
julia> anon_bar = ()->1

doc/src/manual/metaprogramming.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ julia> ex = :(a + b)
364364
:(a + b)
365365
366366
julia> eval(ex)
367-
ERROR: UndefVarError: b not defined
367+
ERROR: UndefVarError: `b` not defined
368368
[...]
369369
370370
julia> a = 1; b = 2;

doc/src/manual/modules.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ julia> using .A, .B
281281
282282
julia> f
283283
WARNING: both B and A export "f"; uses of it in module Main must be qualified
284-
ERROR: UndefVarError: f not defined
284+
ERROR: UndefVarError: `f` not defined
285285
```
286286

287287
Here, Julia cannot decide which `f` you are referring to, so you have to make a choice. The following solutions are commonly used:
@@ -397,7 +397,7 @@ x = 0
397397

398398
module Sub
399399
using ..TestPackage
400-
z = y # ERROR: UndefVarError: y not defined
400+
z = y # ERROR: UndefVarError: `y` not defined
401401
end
402402

403403
y = 1
@@ -413,7 +413,7 @@ For similar reasons, you cannot use a cyclic ordering:
413413
module A
414414

415415
module B
416-
using ..C # ERROR: UndefVarError: C not defined
416+
using ..C # ERROR: UndefVarError: `C` not defined
417417
end
418418

419419
module C

doc/src/manual/variables-and-scoping.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ julia> module B
9090
julia> module D
9191
b = a # errors as D's global scope is separate from A's
9292
end;
93-
ERROR: UndefVarError: a not defined
93+
ERROR: UndefVarError: `a` not defined
9494
```
9595

9696
If a top-level expression contains a variable declaration with keyword `local`,
@@ -187,7 +187,7 @@ julia> greet()
187187
hello
188188
189189
julia> x # global
190-
ERROR: UndefVarError: x not defined
190+
ERROR: UndefVarError: `x` not defined
191191
```
192192

193193
Inside of the `greet` function, the assignment `x = "hello"` causes `x` to be a new local variable
@@ -256,7 +256,7 @@ julia> sum_to(10)
256256
55
257257
258258
julia> s # global
259-
ERROR: UndefVarError: s not defined
259+
ERROR: UndefVarError: `s` not defined
260260
```
261261

262262
Since `s` is local to the function `sum_to`, calling the function has no effect on the global
@@ -343,7 +343,7 @@ hello
343343
hello
344344
345345
julia> x
346-
ERROR: UndefVarError: x not defined
346+
ERROR: UndefVarError: `x` not defined
347347
```
348348

349349
Since the global `x` is not defined when the `for` loop is evaluated, the first clause of the soft
@@ -408,7 +408,7 @@ julia> code = """
408408
julia> include_string(Main, code)
409409
┌ 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.
410410
└ @ string:4
411-
ERROR: LoadError: UndefVarError: s not defined
411+
ERROR: LoadError: UndefVarError: `s` not defined
412412
```
413413

414414
Here we use [`include_string`](@ref), to evaluate `code` as though it were the contents of a file.
@@ -559,7 +559,7 @@ julia> let x = 1, z
559559
println("z: $z") # errors as z has not been assigned yet but is local
560560
end
561561
x: 1, y: -1
562-
ERROR: UndefVarError: z not defined
562+
ERROR: UndefVarError: `z` not defined
563563
```
564564

565565
The assignments are evaluated in order, with each right-hand side evaluated in the scope before

stdlib/REPL/test/repl.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ fake_repl() do stdin_write, stdout_read, repl
14441444
# generate top-level error
14451445
write(stdin_write, "foobar\n")
14461446
readline(stdout_read)
1447-
@test readline(stdout_read) == "\e[0mERROR: UndefVarError: foobar not defined"
1447+
@test readline(stdout_read) == "\e[0mERROR: UndefVarError: `foobar` not defined"
14481448
@test readline(stdout_read) == ""
14491449
readuntil(stdout_read, "julia> ", keep=true)
14501450
# check that top-level error did not change `err`
@@ -1458,13 +1458,13 @@ fake_repl() do stdin_write, stdout_read, repl
14581458
readuntil(stdout_read, "julia> ", keep=true)
14591459
write(stdin_write, "foo()\n")
14601460
readline(stdout_read)
1461-
@test readline(stdout_read) == "\e[0mERROR: UndefVarError: foobar not defined"
1461+
@test readline(stdout_read) == "\e[0mERROR: UndefVarError: `foobar` not defined"
14621462
readuntil(stdout_read, "julia> ", keep=true)
14631463
# check that deeper error did set `err`
14641464
write(stdin_write, "err\n")
14651465
readline(stdout_read)
14661466
@test readline(stdout_read) == "\e[0m1-element ExceptionStack:"
1467-
@test readline(stdout_read) == "UndefVarError: foobar not defined"
1467+
@test readline(stdout_read) == "UndefVarError: `foobar` not defined"
14681468
@test readline(stdout_read) == "Stacktrace:"
14691469
write(stdin_write, '\x04')
14701470
Base.wait(repltask)

test/client.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nested_error_pattern = r"""
1212
ERROR: DivideError: integer division error
1313
Stacktrace:.*
1414
15-
caused by: UndefVarError: __not_a_binding__ not defined
15+
caused by: UndefVarError: `__not_a_binding__` not defined
1616
Stacktrace:.*
1717
"""s
1818

@@ -31,7 +31,7 @@ nested_error_pattern = r"""
3131
DivideError: integer division error
3232
Stacktrace:.*
3333
34-
caused by: UndefVarError: __not_a_binding__ not defined
34+
caused by: UndefVarError: `__not_a_binding__` not defined
3535
Stacktrace:.*
3636
"""s, sprint(show, excs))
3737
end

test/errorshow.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ let undefvar
343343
err_str = @except_str Vector{Any}(undef, 1)[1] UndefRefError
344344
@test err_str == "UndefRefError: access to undefined reference"
345345
err_str = @except_str undefvar UndefVarError
346-
@test err_str == "UndefVarError: undefvar not defined"
346+
@test err_str == "UndefVarError: `undefvar` not defined"
347347
err_str = @except_str read(IOBuffer(), UInt8) EOFError
348348
@test err_str == "EOFError: read end of file"
349349
err_str = @except_str Dict()[:doesnotexist] KeyError

0 commit comments

Comments
 (0)