Skip to content

Commit c3c593c

Browse files
committed
Fix issue where it wasn't possible to inherit from entity with Relationship trait
1 parent b189eae commit c3c593c

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

distr/flecs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5296,6 +5296,7 @@ void flecs_bootstrap(
52965296
/* Sync properties of ChildOf and Identifier with bootstrapped flags */
52975297
ecs_add_pair(world, EcsChildOf, EcsOnDeleteTarget, EcsDelete);
52985298
ecs_add_id(world, EcsChildOf, EcsTrait);
5299+
ecs_add_id(world, EcsIsA, EcsTrait);
52995300
ecs_add_id(world, EcsChildOf, EcsAcyclic);
53005301
ecs_add_id(world, EcsChildOf, EcsTraversable);
53015302
ecs_add_pair(world, EcsChildOf, EcsOnInstantiate, EcsDontInherit);
@@ -39604,7 +39605,7 @@ void flecs_component_record_check_constraints(
3960439605
/* Can't use relationship as target */
3960539606
if (ecs_has_id(world, tgt, EcsRelationship)) {
3960639607
if (!ecs_id_is_wildcard(rel) &&
39607-
!ecs_has_id(world, rel, EcsTrait))
39608+
!ecs_has_id(world, rel, EcsTrait))
3960839609
{
3960939610
ecs_throw(ECS_CONSTRAINT_VIOLATED, "cannot use '%s' as target"
3961039611
" in pair '%s': '%s' has the Relationship trait",

src/bootstrap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ void flecs_bootstrap(
10601060
/* Sync properties of ChildOf and Identifier with bootstrapped flags */
10611061
ecs_add_pair(world, EcsChildOf, EcsOnDeleteTarget, EcsDelete);
10621062
ecs_add_id(world, EcsChildOf, EcsTrait);
1063+
ecs_add_id(world, EcsIsA, EcsTrait);
10631064
ecs_add_id(world, EcsChildOf, EcsAcyclic);
10641065
ecs_add_id(world, EcsChildOf, EcsTraversable);
10651066
ecs_add_pair(world, EcsChildOf, EcsOnInstantiate, EcsDontInherit);

src/storage/component_index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void flecs_component_record_check_constraints(
393393
/* Can't use relationship as target */
394394
if (ecs_has_id(world, tgt, EcsRelationship)) {
395395
if (!ecs_id_is_wildcard(rel) &&
396-
!ecs_has_id(world, rel, EcsTrait))
396+
!ecs_has_id(world, rel, EcsTrait))
397397
{
398398
ecs_throw(ECS_CONSTRAINT_VIOLATED, "cannot use '%s' as target"
399399
" in pair '%s': '%s' has the Relationship trait",

test/core/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,8 @@
18481848
"value_pair_to_str",
18491849
"has_value_pair_wildcard",
18501850
"has_value_pair_any",
1851-
"target_w_value_pair"
1851+
"target_w_value_pair",
1852+
"inherit_relationship_trait"
18521853
]
18531854
}, {
18541855
"id": "Trigger",

test/core/src/Pairs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,3 +3449,16 @@ void Pairs_target_w_value_pair(void) {
34493449

34503450
ecs_fini(world);
34513451
}
3452+
3453+
void Pairs_inherit_relationship_trait(void) {
3454+
ecs_world_t *world = ecs_mini();
3455+
3456+
ecs_entity_t base = ecs_new(world);
3457+
ecs_add_id(world, base, EcsRelationship);
3458+
3459+
ecs_entity_t derived = ecs_new_w_pair(world, EcsIsA, base);
3460+
test_assert(ecs_has_id(world, derived, EcsRelationship));
3461+
3462+
ecs_fini(world);
3463+
}
3464+

test/core/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,7 @@ void Pairs_value_pair_to_str(void);
17861786
void Pairs_has_value_pair_wildcard(void);
17871787
void Pairs_has_value_pair_any(void);
17881788
void Pairs_target_w_value_pair(void);
1789+
void Pairs_inherit_relationship_trait(void);
17891790

17901791
// Testsuite 'Trigger'
17911792
void Trigger_on_add_trigger_before_table(void);
@@ -10171,6 +10172,10 @@ bake_test_case Pairs_testcases[] = {
1017110172
{
1017210173
"target_w_value_pair",
1017310174
Pairs_target_w_value_pair
10175+
},
10176+
{
10177+
"inherit_relationship_trait",
10178+
Pairs_inherit_relationship_trait
1017410179
}
1017510180
};
1017610181

@@ -16015,7 +16020,7 @@ static bake_test_suite suites[] = {
1601516020
"Pairs",
1601616021
NULL,
1601716022
NULL,
16018-
135,
16023+
136,
1601916024
Pairs_testcases
1602016025
},
1602116026
{

0 commit comments

Comments
 (0)