Skip to content

Instantly share code, notes, and snippets.

@kaiser185
Created Nov 23, 2020
Embed
What would you like to do?
Type system bug with debug mode compilation
:- initialization((
logtalk_load([meta(loader), types(loader), debugger(loader)], [debug(on)]),
logtalk_load([simpletypes, parametric], [debug(on)])
)).
:- object(t1(_ListOfT2s_, _SomeId_)).
:- end_object.
:- object(t2(_SomeParameter_)).
:- end_object.
:- category(simpletypes).
:- multifile(type::type/1).
type::type(t1).
type::type(t2).
:- multifile(type::check/2).
type::check(t1, Term) :-
check_t1(Term).
type::check(t2, Term) :-
check_t2(Term).
check_t1(Term) :-
Term = t1(ListOfT2s, Id),
type::check(atomic, Id),
type::check(
property(non_empty_list(object), [T2s]>>(
meta::map([T2]>>(
type::check(t2, T2)
), T2s)
)
), ListOfT2s).
check_t2(Term) :-
Term = t2(Param),
type::check(atomic, Param).
:- end_category.
@kaiser185

This comment has been minimized.

Copy link
Owner Author

@kaiser185 kaiser185 commented Nov 23, 2020

Here's how to reproduce the bug

?- Term = t1([t2(aaa), t2(bbb)], ccc), type::check(t1, Term).
false.

?- debugger::trace.
true.

?- Term = t1([t2(aaa), t2(bbb)], ccc), type::check(t1, Term).
   Rule: (0) type::check(t1,t1([t2(aaa),t2(bbb)],ccc)) ? s
Term = t1([t2(aaa), t2(bbb)], ccc).

If we change the loader to (by commenting out the the debug(on) options of the logtalk_load/2 predicate):

:- initialization((
	logtalk_load([meta(loader), types(loader), debugger(loader)], [/* debug(on) */]),
	logtalk_load([simpletypes, parametric], [/* debug(on) */])
)).

The query works as expected:

?- Term = t1([t2(aaa), t2(bbb)], ccc), type::check(t1, Term).
Term = t1([t2(aaa), t2(bbb)], ccc).

Note that in this case we use no SWI-Prolog specific features like dicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment