Files
mercury/tests/invalid/html.m
Zoltan Somogyi 4ebe95672d Don't crash on inst_name nested inside itself.
This fixes Mantis bug #528.

compiler/error_msg_inst.m:
    Since an inst_name IN may be used nested inside itself, as in
    IN(..., IN(...), ...), do not insist that both occurrences of IN
    in such cases lead to the insertion of a new entry in the inst name
    expansion map.

tests/invalid/html.{m,err_exp}:
    The Mantis test case.

tests/invalid/Mmakefile:
    Enable the Mantis test case.
2021-01-30 01:45:26 +11:00

60 lines
1.9 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ff=unix ts=4 sw=4 et
%-----------------------------------------------------------------------------%
:- module html.
:- interface.
:- import_module io.
:- import_module list.
%-----------------------------------------------------------------------------%
% Elements that are allowed inside the body tag of an HTML document
%
:- type body_elem
---> ul(list(body_elem)) % Unordered list tag
; li(list(body_elem)) % List item tag
; text(string).
%-----------------------------------------------------------------------------%
% Top-level body elements.
% The li tag is not allowed as a top-level element. It must be a direct
% child of the ul tag.
%
:- inst top_body_elem for body_elem/0
---> ul(non_empty_list(li(top_body_elem)))
% The ul tag allows only li tags as top level children.
; text(ground).
:- inst li(I) for body_elem/0
---> li(non_empty_list(I)).
%-----------------------------------------------------------------------------%
:- inst non_empty_list(I) for list/1
---> [I | list_skel(I)].
%-----------------------------------------------------------------------------%
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
%-----------------------------------------------------------------------------%
main(!IO).
:- func init_body_elem =
(list(body_elem)::out(non_empty_list(top_body_elem))) is det.
init_body_elem =
% [ul([li([text("List item")])])]. % This line compiles without errors
[ul([li([])])].
% This line causes compiler abort
% Expected result: mode checker error because of violated inst rule
% (li tag requires non-empty list as argument)