From 137be9701bc36d93822b0b9e8e98527a5ec0cdd6 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Thu, 28 Sep 2023 12:49:30 +1000 Subject: [PATCH] Fix false residuals, re issue #350 --- src/unify.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/unify.c b/src/unify.c index f37dfd618..7dc3d8030 100644 --- a/src/unify.c +++ b/src/unify.c @@ -95,15 +95,16 @@ static int compare_structs(query *q, cell *p1, pl_idx p1_ctx, cell *p2, pl_idx p DEREF_SLOT(both, save_vgen2, e2, e2->vgen2, c2, c2_ctx, q->vgen); bool cycle2 = both ? true : false; - if (cycle1 && !cycle2) - return 1; - - if (!cycle1 && cycle2) - return -1; - if (!cycle1 && !cycle2) { int val = compare_internal(q, c1, c1_ctx, c2, c2_ctx, depth+1); if (val) return val; + } else if (cycle1 != cycle2) { + c1 = deref(q, p1, p1_ctx); + c1_ctx = q->latest_ctx; + c2 = deref(q, p2, p2_ctx); + c2_ctx = q->latest_ctx; + int val = compare_internal(q, c1, c1_ctx, c2, c2_ctx, depth+1); + if (val) return val; } if (e1) e1->vgen = save_vgen1;