gprolog builtin phrase/3 incorrectly succeeds when matching constant lists

Bug #1946197 reported by ais523
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gprolog (Ubuntu)
New
Undecided
Unassigned

Bug Description

gprolog seems to be producing incorrect results when using the phrase/3 builtin. In particular, the symptom is that when phrase/3 is used to match a DCG that requires its input to start with a particular string/list, and the input actually starts with something else, phrase/3 reports that there was a match (returning an unbound list for the remaining unconsumed input), rather than reporting that there was no match.

Example to reproduce: start gprolog, and give it the input line

phrase([2], [1,2], T).

Expected behaviour: gprolog answers "no": this query is equivalent to "remove the prefix [2] from the list [1,2] and bind the remainder to T", and [1,2] does not start with [2], so this task should be impossible. I've verified that this is the expected/correct output against both gprolog's documentation, and against swipl (a different Prolog implementation).

Actual behaviour: gprolog answers "yes", without binding anything to T (it remains an unbound variable).

The problem seems to be specific to the case of there being no match; with the comparable

phrase([1], [1,2], T).

gprolog will produce the output of "T=[2]" and "yes" (the expected output), and will not suggest a second solution with T unbound.

It's also specific to the use of phrase/3 for evaluating DCG literals directly; using the --> operator to give a name to the grammar consisting only of [2], then executing that grammar (whether directly or with phrase/3), produces the correct results.

phrase/2 seems to have the same buggy behaviour as phrase/3 (probably because it's implemented as calling phrase/3 behind the scenes).

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: gprolog 1.4.5.0-3
ProcVersionSignature: Ubuntu 5.4.0-84.94-generic 5.4.133
Uname: Linux 5.4.0-84-generic x86_64
ApportVersion: 2.20.11-0ubuntu27.20
Architecture: amd64
CasperMD5CheckResult: skip
CurrentDesktop: X-Cinnamon
Date: Wed Oct 6 08:42:51 2021
ExecutablePath: /usr/lib/gprolog/bin/gprolog
InstallationDate: Installed on 2019-11-11 (694 days ago)
InstallationMedia: Ubuntu 18.04.3 LTS "Bionic Beaver" - Release amd64 (20190805)
SourcePackage: gprolog
UpgradeStatus: Upgraded to focal on 2020-10-02 (368 days ago)

Revision history for this message
ais523 (ais523) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.