From 5da14d502827fac5b326e465a8eeedf9412602f8 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:21:10 -0500 Subject: [PATCH] Fix `exhaustive.jl` test error Identified in https://github.com/JuliaDebug/Cthulhu.jl/pull/585 --- src/utils.jl | 8 ++++++++ test/runtests.jl | 6 ++++++ test/script.jl | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 6927e54..bd1c641 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -111,7 +111,15 @@ function is_func_expr(@nospecialize(ex), meth::Method) end end found && break + if isexpr(whereex, :(::)) + typeex = whereex.args[end] + if isexpr(typeex, :curly) && typeex.args[1] === :Type + fname = typeex.args[2] + break + end + end whereex = whereex.args[1] + isa(whereex, Expr) || return false end end # match the function name diff --git a/test/runtests.jl b/test/runtests.jl index d4ae8b8..cb45c49 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -247,6 +247,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j src, line = definition(String, m) @test occursin("(::Type{T})(itr) where {T<:Invert}", src) @test line == 126 + m = @which MyArray1{Float64, 1}(undef, 5) + src, line = definition(String, m) + @test occursin("(self::Type{MyArray1{T,1}})(::UndefInitializer", src) + m = @which MyArray2{Float64, 1}(undef, 5) + src, line = definition(String, m) + @test occursin("(::Type{MyArray2{T,1}})(::UndefInitializer", src) # Invalidation-insulating methods used by Revise and perhaps others d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}() diff --git a/test/script.jl b/test/script.jl index 1a4ea14..f74a7e8 100644 --- a/test/script.jl +++ b/test/script.jl @@ -146,3 +146,17 @@ only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, bu # Nested `where`s struct Parametric{N} end (::Type{P})(x::Int) where P<:Parametric{N} where N = P() + +# `where`s that are not simply `(::Type{T})(args...) where T<:SomeSpecialType` +struct MyArray1{T,N} + data::T +end +function (self::Type{MyArray1{T,1}})(::UndefInitializer, m::Int) where {T} + return nothing +end +struct MyArray2{T,N} + data::T +end +function (::Type{MyArray2{T,1}})(::UndefInitializer, m::Int) where {T} + return nothing +end