Closed lngns closed 4 years ago
Generic type parameters in Skew are associated with the type itself, not with instances. This is sort of like templates in C++ where the namespace Vector<int>
is separate from the namespace Vector<double>
. So in your example, you should only need to write Vector<T>.stackalloc(12)
since stackalloc
should already have access to the T
type parameter because it's inside the Vector<T>
namespace. Note that even though namespace Vector
isn't written namespace Vector<T>
, it still has access to T
if it was merged with class Vector<T>
.
it still has access to T if it was merged with class Vector
.
Oh right, I never tested it that way. I think it makes sense, especially with open classes that have a similar-ish behaviour. The docs don't make it obvious imo though.
Thanks! Nice to see the project's still well, by the way.
Accessing symbols in a namespace merged with a generic type requires passing the type arguments to the namespace. So for
class Vector<T>
andnamespace Vector
, if I want to call a function from the latter, I may need to writeVector<T>.stackalloc<T>(12)
, which makes it redundant as namespaces can't access generic parameters by themselves.Are there plans to allow namespaces to access type parameters like
namespace Vector<T>
, or is it a bug in the name resolution where the type has higher priority than the ns?