In the following two somewhat similar chunks of code the first generates an error, the other does not. Any ideas about why?
using DataFrames, Dates
NT1 = NamedTuple{(:DFPrecalc,:VPrecalc), Tuple{DataFrame,S}} where S
nt1 = (DFPrecalc = DataFrame(:A => [1]), VPrecalc = [Dates.today()])
cv1 = convert(NT1, nt1)
ERROR: UndefVarError: T not defined
Stacktrace:
[1] convert(#unused#::Type{NamedTuple{(:DFPrecalc, :VPrecalc), Tuple{DataFrame, S}} where S}, nt::NamedTuple{(:DFPrecalc, :VPrecalc), Tuple{DataFrame, Vector{Date}}})
@ Base .\namedtuple.jl:151
[2] top-level scope
@ REPL[4]:1
NT2 = NamedTuple{(:A,:B), Tuple{Int,Vector{T}}} where T
nt2 = (A = 1, B = [1])
cv2 = convert(NT2, nt2)
(A = 1, B = [1])
After looking at the comments and making some mistakes I realized that the problem is that the parameter S is representing a Vector. So if the second example is modified to have the parameter S to represent the vector and not the eltype of the vector the code does not work, as in the first example. This is shown below.
NT3 = NamedTuple{(:A,:B), Tuple{Int,S}} where S
nt3 = (A = 1, B = [1])
cv3 = convert(NT3, nt3)
ERROR: UndefVarError: T not defined
Stacktrace:
[1] convert(#unused#::Type{NamedTuple{(:A, :B), Tuple{Int64, T}} where T}, nt::NamedTuple{(:A, :B), Tuple{Int64, Vector{Int64}}})
@ Base .\namedtuple.jl:151
[2] top-level scope
@ REPL[32]:1