-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't inherit from generic of nested class #5031
Comments
Not sure if this is a best solution, but you can use
https://carc.in/#/r/2sg9 |
is the (just curious because I am new) |
@monouser7dig i guess i could just say @konovod that could work. i'm ok with composition over inheritance, but i didn't realize we had that macro. it does more or less solve the problem, but i still feel that |
Answers from my point of view:
So I'd close this issue. The problem can be solved without requiring language changes. |
@asterite yea, after submitting the issue and thinking about it more for the past few days i have arrived at more or less the same conclusion as your first and second points, especially after what @konovod said. i did expect your third point would be true... and probably would require cascading language changes. so i agree and i will close it. |
The code
The compile:
Why this is a problem:
As you can see
Book::Page
andNewsPaper::Page
are wholly different types but they are still "pages," with respect to their outer types, and their names should reflect this, but they belong in different subtypes.Writing another class just called
Page
outside ofBook
andNewspaper
, does not make sense, as they have different attributes, and thus different behavior, despite still both being "pages"Writing it as generic
Page(T)
(Page(Book)
orPage(NewsPaper)
) is both misleading and tedious, and still preempts the flexibility offered by namespaces.It is possible to simply write
NewsPaperPage
andBookPage
to get around this, but in my opinion that makes organizing the project messy. Additionally, their definition is less expressive as you refer them in the same namespace as the class which is supposed to contain them.This isn't a huge deal as i can easily just make a wrapper class which delegates to the array...
...but this would mean re-writing every method (or at least the ones i foresee using) from
Array(T)
and using it on@pages
which isn't great either. I guess the solution isBook.new.pages[0]
or something.Questions:
Array(T)
at the time of declaring inheritance? Of course, they must get defined before the end of input, but is it critical for that definition ofT
to be fully and completely fleshed out as of this lineclass Something < Generic(T)
?T
ofArray(T)
abstract throughout class definition, and then:T
doesn't get any definition later, raise an error?T
does get defined later, close the loop on inheritance?It does seem like it would be more than just an insertion of some conditional reasoning and might require some in depth thought and possibly a large rework of how the compiler assess type values to support this.
Comments
I checked #2665 and was surprised I didn't find any issues were like this one. It seems like someone would have encountered this before me, so I apologize if this is a duplicate... but I didn't find any.
The text was updated successfully, but these errors were encountered: