LogtalkDotOrg / logtalk3

Logtalk - declarative object-oriented logic programming language
https://logtalk.org
Apache License 2.0
425 stars 31 forks source link

Local non-terminal metas in lgtunit #222

Closed cl-alexk closed 5 months ago

cl-alexk commented 5 months ago
:- object(state).
    :- public(return//1).
    return(R, [_], [R]).
    % return(R), [_] --> [R]. % does not make a difference

    :- public(run/2).
    :- meta_predicate(run(2,*)).
    run(G, S) :- phrase(G, [], S).
:- end_object.

:- object(test, extends([state, lgtunit])).
    t --> ::return(true).
    test(closure0, deterministic) :-
        ::run(t, [true]).
:- end_object.
% swilgt -q
?- {lgtunit(loader)}.
true.

?- logtalk_load(meta3, [hook(lgtunit)]).
true.

?- test::run.
...
!     closure0: failure (in 0.000374000/0.001000000 cpu/wall seconds)
!       test goal throws an error but should have succeeded: error(existence_error(procedure,'$lgtunit#0.t#2'/3),logtalk(call(t([],[true])),c(lgtunit,lgtunit,r(test,test,[],[]))))
pmoura commented 5 months ago

I get (with 9f87ec366dfef657ba70ebf4f0f1fdb465cff395):

?- test::run.
% 
% tests started at 2024-06-28, 12:11:35
% 
% running tests from object test
% file: /Users/pmoura/Downloads/state.lgt
% 
!     closure0: failure (in 0.000047000/0.000000000 cpu/wall seconds)
!       test goal failed but should have succeeded
!       in file /Users/pmoura/Downloads/state.lgt between lines 13-14
!     
% 
% 1 tests: 0 skipped, 0 passed, 1 failed (0 flaky)
% runtime: 0.000047000/0.000000000 cpu/wall seconds
% completed tests from object test
% 
% no code coverage information collected
% tests ended at 2024-06-28, 12:11:35
% 
true.

No error.

pmoura commented 5 months ago

Try (simpler):

:- object(state).

    :- protected(run/2).
    :- meta_predicate(run(1,*)).
    run(G, S) :-
        phrase(G, [S]).

:- end_object.

:- object(odd, extends((state, lgtunit))).

    t --> [true].

    test(closure0, deterministic(S == true)) :-
        ::run(t, S).

:- end_object.
$ swilgt -q
?- {lgtunit(loader)}.
true.

?- logtalk_load(odd, [hook(lgtunit)]).
true.

?- odd::run.
% 
% tests started at 2024-06-28, 12:17:40
% 
% running tests from object odd
% file: /Users/pmoura/Downloads/odd.lgt
% 
% closure0: success (in 0.000074000/0.001000000 cpu/wall seconds)
% 
% 1 tests: 0 skipped, 1 passed, 0 failed (0 flaky)
% runtime: 0.000074000/0.001000000 cpu/wall seconds
% completed tests from object odd
% 
% no code coverage information collected
% tests ended at 2024-06-28, 12:17:40
% 
true.
pmoura commented 5 months ago

With this change to your example:

return(R, [], [R]).

I get:

?- test::run.
% 
% tests started at 2024-06-28, 12:33:39
% 
% running tests from object test
% file: /Users/pmoura/Downloads/state.lgt
% 
% closure0: success (in 0.000168000/0.000000000 cpu/wall seconds)
% 
% 1 tests: 0 skipped, 1 passed, 0 failed (0 flaky)
% runtime: 0.000168000/0.000000000 cpu/wall seconds
% completed tests from object test
% 
% no code coverage information collected
% tests ended at 2024-06-28, 12:33:39
% 
true.
cl-alexk commented 5 months ago

Thank you. Apparently my local install is somehow not getting this recent change via install.sh script.