didoudiaz / gprolog

GNU Prolog
Other
106 stars 13 forks source link

Bug in the implementation of conditional compilation directives #39

Closed pmoura closed 1 year ago

pmoura commented 1 year ago

Running the Logtalk test set for conditional compilation directives (git version) shows a failed test:

$ logtalk_tester -p gnu
% Batch testing started @ 2023-06-07 19:29:58
%         Logtalk version: 3.67.0-b01
%         GNU Prolog version: 1.6.0
%
% Documents/Logtalk/logtalk3/tests/prolog/directives/conditional_compilation
%         39 tests: 0 skipped, 38 passed, 1 failed (0 flaky)
%         completed tests from object tests in 3 seconds
%         clause coverage n/a
%
% Compilation errors/warnings and failed unit tests
% (compilation errors/warnings might be expected depending on the test)
!     conditional_compilation_f22: failure (in 0.0 seconds)
!       test goal succeeded but should have failed
!       in file Documents/Logtalk/logtalk3/tests/prolog/directives/conditional_compilation/tests.lgt between lines 123-124
%
% Failed tests
Documents/Logtalk/logtalk3/tests/prolog/directives/conditional_compilation/tests.lgt - conditional_compilation_f22 @ tests
%
% 1 test sets: 1 completed, 0 skipped, 0 broken, 0 timedout, 0 crashed
% 39 tests: 0 skipped, 38 passed, 1 failed (0 flaky)
%
% Batch testing ended @ 2023-06-07 19:30:02

A simplified test file that exposes the same bug is:

:- if(fail).
    f20.
:- elif(fail).
    f21.
    :- if(true).
        f22.
    :- elif(true).
        f23.
    :- else.
        f24.
    :- endif.
:- elif(fail).
    f25.
:- else.
    s7.
:- endif.

After loading it:

$ gprolog
GNU Prolog 1.6.0 (64 bits)
Compiled Jun  7 2023, 16:40:18 with /opt/local/bin/gcc-mp-12
Copyright (C) 1999-2023 Daniel Diaz

| ?- [ccbug].
compiling /Users/pmoura/ccbug.pl for byte code...
/Users/pmoura/ccbug.pl compiled, 16 lines read - 272 bytes written, 3 ms

yes
| ?- f22.

yes

Only the call to s7 should succeed; Calling any of the fXX predicates should throw an existence error.

pmoura commented 1 year ago

Fix confirmed. Thanks!