Open itspomf opened 3 months ago
!nim c
import std/tables
import std/sequtils
type
Component* = object of RootObj
Subtree[T] = OrderedTableRef[ typedesc[T], seq[T] ]
let universe = newOrderedTable[ string, Subtree[ Component ]]()
proc drop*[T: Component]( uuid: string, components: seq[T] ) =
universe.withValue( uuid, branch ):
branch.withValue( T, leaf ):
for component in components:
leaf.del( component )
proc put*[T: Component]( uuid: string, components: seq[T] ) =
let branch = universe.mgetOrPut( uuid, Subtree[T]() )
if not branch.hasKey( T ):
branch[T] = components
else:
branch.withValue( T, leaf ):
for component in components:
if component notin leaf:
leaf.add( component )
type
Dummy = object of Component
value: int
let d0 = Dummy( value: 0 )
echo $d0
put("zero", @[ d0 ])
0 (0 bytes)
```cpp
```
2024-07-31T20:22:36
2024-07-31T20:22:37
0 (0 bytes)
```cpp
```
2024-07-31T20:22:41
2024-07-31T20:22:41
0 (0 bytes)
```cpp
```
2024-07-31T20:22:44
2024-07-31T20:22:44
0 (0 bytes)
```cpp
```
2024-07-31T20:22:48
2024-07-31T20:22:48
0 (0 bytes)
```cpp
```
2024-07-31T20:22:50
2024-07-31T20:22:51
0 (0 bytes)
```cpp
```
2024-07-31T20:22:53
2024-07-31T20:22:53
0 (0 bytes)
```cpp
```
2024-07-31T20:22:56
2024-07-31T20:22:56
0 (0 bytes)
```cpp
```
2024-07-31T20:22:58
2024-07-31T20:22:58
11.4.0
14.0.0
20.4
2024-07-31T20:22:09Z
1
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 25 minutes
bisecting 8
commits at 0
commits per second
Description
I'm using the playground to try to test out the creation of a simple entity-component relational model in Nim, using generics.
The following code example shows the situation and the test scenario of assigning a single component to an entity.
Nim Version
Using "latest" (via NimPlayground)
Current Output
Expected Output
Possible Solution
No response
Additional Information
As best I can tell from the debugger's output, it's correctly recognizing that I wish to create a
Subtree
ofDummy
(position 3), but fails to assert that Dummy is an object of Component, despite passing the constraint of[T: Component]
to reach line 17.Since the currently available documentation on the nim-lang.org site does not provide guidance on inheritance in generics (or how to explicitly declare this via a type constraint), I would assume that this should resolve normally.
Searching the bug list, this might be related to #88.