Closed Socob closed 23 hours ago
This is correct. The value of T
is only defined for well-formed types, and the TypeVar constructor does not make well-formed types. You must use func(T::Type) = T
if you want to return the actual input, rather that an arbitrary transform of the input (including potentially transforming it into not having a value)
Fair enough, but I don’t see how I’d be expected to know that T
could ever end up being undefined? Like I said, a better error would be nice – I think it’d be much better if an error is thrown whenever a construction like this results in T
being undefined, rather than only throwing an error when it’s used.
There is no way for it to know that you would later construct a malformed type using the private TypeVar constructor
I mean when calling the function. I don’t see why there couldn’t be an error if T
is undefined at the beginning of the function?
Also, in what sense is the TypeVar
constructor private? It seems to be exported by Core
?
Type constructors are default private, even if the type object itself may be visible (e.g. for dispatch purposes)
When passing a type which has a
TypeVar
parameter to a parametric function, the result is the following unexpectedUndefVarError
about the function parameter:The expected result would of course be
Array{Float64, TypeVar(:N)}
, not an error.Although I’m only using exported symbols in the example above, I suspect that this might not necessarily be a supported use (?). Even if this is the case, I think at least the error should be fixed, since as it stands it’s completely misleading.
Info:
The output of
versioninfo()
:How you installed Julia: juliaup
A minimal working example (MWE): see above