crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.42k stars 1.62k forks source link

Docs should distinguish between non-instantiated and instantiated generic vars #10215

Open HertzDevil opened 3 years ago

HertzDevil commented 3 years ago

The documentation generated from the following code

module Foo(T)
end

class Bar(T)
  include Foo(Bar)
  include Foo(Bar(T))
end

shows that Bar includes Foo(Bar(T)) twice:

Screenshot_20210107_202848

However the two includes have different semantics, which are evident when Foo is a module like Comparable: (this happens to most collection types in the standard library, actually)

class Bar(T)
  # all Bars are comparable with each other
  include Comparable(Bar)
  # Bar(T) is only comparable with Bar(T); mixing generic type arguments is not allowed
  include Comparable(Bar(T))
end

Thus the links generated from types should omit the type vars if a generic type argument is non-instantiated. This applies especially to the type lists on the top of each page (included / extended modules, subclasses, including types).

asterite commented 3 years ago

Foo(Bar) shouldn't compile there

HertzDevil commented 3 years ago

So what do all containers like Array do then? include Comparable(Array(U) forall U)?

asterite commented 3 years ago

Oh, I see. I didn't know this was already in use. I guess it's fine then...