Skip to content

Commit 3fb12e4

Browse files
authored
Fix lookup for PartialStruct constructors (#107)
1 parent 8a990ea commit 3fb12e4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function checkname(fdef::Expr, name)
66
fdef.head === :call || return false
77
if fproto isa Expr
88
fproto.head == :(::) && return last(fproto.args) == name
9+
fproto.head == :curly && return fproto.args[1] === name
910
# A metaprogramming-generated function
1011
fproto.head === :$ && return true # uncheckable, let's assume all is well
1112
# Is the check below redundant?

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
8787
@test pkgfiles("ColorTypes") === nothing
8888
@test_throws ErrorException pkgfiles("NotAPkg")
8989

90+
# PartialStruct parametric constructors
91+
m = @which LikeNamedTuple{(:a,)}((1,))
92+
_, line = whereis(m)
93+
def, linedef = definition(String, m)
94+
@test line == linedef
95+
@test occursin("LikeNamedTuple{names}", def)
96+
9097
# Test a method marked as missing
9198
m = @which sum(1:5)
9299
CodeTracking.method_info[m.sig] = missing

test/script.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ if isdefined(Base, Symbol("@assume_effects"))
6868
end
6969

7070
has_semicolon1(x, y) = x + y;
71+
72+
struct LikeNamedTuple{names,V}
73+
vals::V
74+
end
75+
76+
LikeNamedTuple() = LikeNamedTuple{(),Tuple{}}(())
77+
78+
LikeNamedTuple{names}(args::Tuple) where {names} = LikeNamedTuple{names,typeof(args)}(args)

0 commit comments

Comments
 (0)