From b379f0142778afc8b3dbbe8574ef8d9ae34afe07 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 28 Jul 2021 03:43:17 -0500 Subject: [PATCH] Fix `definition` for return-type annotations Fixes #81 --- src/utils.jl | 2 +- test/runtests.jl | 6 ++++++ test/script.jl | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index 9dad520..47eb245 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -2,7 +2,7 @@ # (or change the test) function checkname(fdef::Expr, name) fproto = fdef.args[1] - fdef.head === :where && return checkname(fproto, name) + (fdef.head === :where || fdef.head == :(::)) && return checkname(fproto, name) fdef.head === :call || return false if fproto isa Expr # A metaprogramming-generated function diff --git a/test/runtests.jl b/test/runtests.jl index ee5756d..dd92b68 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -59,6 +59,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j @test occursin("100x", src) @test line == 22 + # Issue #81 + m = which(hasrettype, (Int,)) + src, line = definition(String, m) + @test occursin("Float32", src) + @test line == 43 + info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking)) @test Base.PkgId(info) === info.id @test CodeTracking.basedir(info) == dirname(@__DIR__) diff --git a/test/script.jl b/test/script.jl index 5562579..4f6abb1 100644 --- a/test/script.jl +++ b/test/script.jl @@ -38,3 +38,8 @@ function Foo.Bar.fit(m) end Foo.Bar.fit(a, b) = a + b + +# Issue #81 +function hasrettype(x::Real)::Float32 + return x*x + x +end