From 052b3b7de3f7ceaf0a0f2cedfe756ba66e210b50 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Fri, 23 May 2025 13:31:01 +0200 Subject: [PATCH 1/3] Use type wrapper directly rather than typename in FieldError --- base/errorshow.jl | 4 ++-- test/errorshow.jl | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index 2e798b60cf733..e42ad1d43ae84 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -382,7 +382,7 @@ end function showerror(io::IO, exc::FieldError) @nospecialize - print(io, "FieldError: type $(exc.type |> nameof) has no field `$(exc.field)`") + print(io, "FieldError: type $(exc.type.name.wrapper) has no field `$(exc.field)`") Base.Experimental.show_error_hints(io, exc) end @@ -1127,7 +1127,7 @@ Experimental.register_error_hint(fielderror_dict_hint_handler, FieldError) function fielderror_listfields_hint_handler(io, exc) fields = fieldnames(exc.type) if isempty(fields) - print(io, "; $(nameof(exc.type)) has no fields at all.") + print(io, "; $(exc.type.name.wrapper) has no fields at all.") else print(io, ", available fields: $(join(map(k -> "`$k`", fields), ", "))") end diff --git a/test/errorshow.jl b/test/errorshow.jl index 8d582ba8e538c..20112a1a5feab 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -1332,3 +1332,22 @@ let err_str err_str = @except_str f56325(1,2) MethodError @test occursin("The anonymous function", err_str) end + +@testset "FieldError with changing fields" begin + # https://discourse.julialang.org/t/better-error-message-for-modified-structs-in-julia-1-12/129265 + module FieldErrorTest + struct Point end + p = Point() + end + + err_str1 = @except_str FieldErrorTest.p.x FieldError + @test occursin("FieldErrorTest.Point", err_str1) + + @eval FieldErrorTest struct Point{T} + x::T + y::T + end + err_str2 = @except_str FieldErrorTest.p.x FieldError + @test occursin("@world", err_str2) + @test occursin("FieldErrorTest.Point", err_str2) +end From 1e1aceaad641ab3cce6850f5cfe32f3a728df424 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Fri, 23 May 2025 18:32:10 +0200 Subject: [PATCH 2/3] fix namespacing of old FieldErrorTest --- test/errorshow.jl | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/test/errorshow.jl b/test/errorshow.jl index 20112a1a5feab..ceb2365787f4c 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -880,6 +880,24 @@ end @test occursin(hintExpected, errorMsg) end +module FieldErrorTest +struct Point end +p = Point() +end + +@testset "FieldError with changing fields" begin + # https://discourse.julialang.org/t/better-error-message-for-modified-structs-in-julia-1-12/129265 + err_str1 = @except_str FieldErrorTest.p.x FieldError + @test occursin("FieldErrorTest.Point", err_str1) + @eval FieldErrorTest struct Point{T} + x::T + y::T + end + err_str2 = @except_str FieldErrorTest.p.x FieldError + @test occursin("@world", err_str2) + @test occursin("FieldErrorTest.Point", err_str2) +end + # UndefVar error hints module A53000 export f @@ -1333,21 +1351,5 @@ let err_str @test occursin("The anonymous function", err_str) end -@testset "FieldError with changing fields" begin - # https://discourse.julialang.org/t/better-error-message-for-modified-structs-in-julia-1-12/129265 - module FieldErrorTest - struct Point end - p = Point() - end - err_str1 = @except_str FieldErrorTest.p.x FieldError - @test occursin("FieldErrorTest.Point", err_str1) - @eval FieldErrorTest struct Point{T} - x::T - y::T - end - err_str2 = @except_str FieldErrorTest.p.x FieldError - @test occursin("@world", err_str2) - @test occursin("FieldErrorTest.Point", err_str2) -end From 7335c0cc78d97725a9d57c7c368b86363b7a0545 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Fri, 23 May 2025 18:34:02 +0200 Subject: [PATCH 3/3] whitespace --- test/errorshow.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/errorshow.jl b/test/errorshow.jl index ceb2365787f4c..a16fd7ca71cd3 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -1350,6 +1350,3 @@ let err_str err_str = @except_str f56325(1,2) MethodError @test occursin("The anonymous function", err_str) end - - -