Skip to content

Commit 5fc8fd6

Browse files
committed
Don't use T.parameters to query type parameters
1 parent 4480b8b commit 5fc8fd6

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/types.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,11 @@ function promote_symtype(f::Sym{FnType{X,Y}}, args...) where {X, Y}
215215
return Y
216216
end
217217

218-
nrequired = fieldcount(X)
219-
ngiven = nfields(args)
220-
221-
if nrequired !== ngiven
222-
error("$f takes $nrequired arguments; $ngiven arguments given")
223-
end
224-
225-
for i in 1:ngiven
226-
t = X.parameters[i]
227-
if !(args[i] <: t)
228-
error("Argument to $f at position $i must be of symbolic type $t")
229-
end
218+
# This is to handle `Tuple{T} where T`, so we cannot reliably query the type
219+
# parameters of the `Tuple` in `FnType`.
220+
t = Tuple{args...}
221+
if !(t <: X)
222+
error("$t is not a subtype of $X.")
230223
end
231224
return Y
232225
end
@@ -291,7 +284,9 @@ end
291284

292285
function Base.show(io::IO, f::Sym{<:FnType{X,Y}}) where {X,Y}
293286
print(io, f.name)
294-
argrepr = join(map(t->"::"*string(t), X.parameters), ", ")
287+
# Use `Base.unwrap_unionall` to handle `Tuple{T} where T`. This is not the
288+
# best printing, but it's better than erroring.
289+
argrepr = join(map(t->"::"*string(t), Base.unwrap_unionall(X).parameters), ", ")
295290
print(io, "(", argrepr, ")")
296291
print(io, "::", Y)
297292
end

0 commit comments

Comments
 (0)