nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.63k stars 1.47k forks source link

Cannot inherit from generic forward types #24446

Open metagn opened 1 week ago

metagn commented 1 week ago

Split from #18861

type
  ConnectionRequest* = ref object of RootObj
  ConnectionStrBool* = distinct bool
  ConnectionSetRequest = ref object of ConnectionRequestT[ConnectionStrBool]
  ConnectionRequestT*[T] = ref object of ConnectionRequest
proc execute*(req: ConnectionRequestT[bool]) = discard
proc execute*(req: ConnectionRequestT[ConnectionStrBool]) = discard
ConnectionSetRequest().execute()

Apparently used to give this error:

/tmp/zzz.nim(4, 37) Error: inheritance only works with non-final objects; for ConnectionRequestT[zzz.ConnectionStrBool] to be inheritable it must be 'object of RootObj' instead of 'object', but swapping object declaration order into 

But now segfaults the compiler in lookupInRecordAndBuildCheck called here.

This case also used to not compile:

type
  Foo = object of Bar
  Bar = object of RootObj

and now compiles, but might not work if Foo is used further.

5687 might be related