Skip to content

Commit 052b3b7

Browse files
committed
Use type wrapper directly rather than typename in FieldError
1 parent 6180ca0 commit 052b3b7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

base/errorshow.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ end
382382

383383
function showerror(io::IO, exc::FieldError)
384384
@nospecialize
385-
print(io, "FieldError: type $(exc.type |> nameof) has no field `$(exc.field)`")
385+
print(io, "FieldError: type $(exc.type.name.wrapper) has no field `$(exc.field)`")
386386
Base.Experimental.show_error_hints(io, exc)
387387
end
388388

@@ -1127,7 +1127,7 @@ Experimental.register_error_hint(fielderror_dict_hint_handler, FieldError)
11271127
function fielderror_listfields_hint_handler(io, exc)
11281128
fields = fieldnames(exc.type)
11291129
if isempty(fields)
1130-
print(io, "; $(nameof(exc.type)) has no fields at all.")
1130+
print(io, "; $(exc.type.name.wrapper) has no fields at all.")
11311131
else
11321132
print(io, ", available fields: $(join(map(k -> "`$k`", fields), ", "))")
11331133
end

test/errorshow.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,22 @@ let err_str
13321332
err_str = @except_str f56325(1,2) MethodError
13331333
@test occursin("The anonymous function", err_str)
13341334
end
1335+
1336+
@testset "FieldError with changing fields" begin
1337+
# https://discourse.julialang.org/t/better-error-message-for-modified-structs-in-julia-1-12/129265
1338+
module FieldErrorTest
1339+
struct Point end
1340+
p = Point()
1341+
end
1342+
1343+
err_str1 = @except_str FieldErrorTest.p.x FieldError
1344+
@test occursin("FieldErrorTest.Point", err_str1)
1345+
1346+
@eval FieldErrorTest struct Point{T}
1347+
x::T
1348+
y::T
1349+
end
1350+
err_str2 = @except_str FieldErrorTest.p.x FieldError
1351+
@test occursin("@world", err_str2)
1352+
@test occursin("FieldErrorTest.Point", err_str2)
1353+
end

0 commit comments

Comments
 (0)