evanw / skew

A web-first, cross-platform programming language with an optimizing compiler
https://evanw.github.io/skew-lang.org/
MIT License
411 stars 16 forks source link

Namespaces don't merge correctly with generic types #26

Closed lngns closed 4 years ago

lngns commented 4 years ago

Accessing symbols in a namespace merged with a generic type requires passing the type arguments to the namespace. So for class Vector<T> and namespace Vector, if I want to call a function from the latter, I may need to write Vector<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?

evanw commented 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>.

lngns commented 4 years ago

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.