Mercury Bugs - mercury
View Issue Details
0000528mercuryBugpublic2021-01-29 21:402021-01-30 01:46
Reporterdirkz 
Assigned Tozs 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformMercury 20.06 / rotd-2021-01-27OSMacOS Catalina, IntelOS Version10.15.7
Product Version 
Target VersionFixed in Version 
Summary0000528: Compiler aborts when constructing invalid inst
DescriptionI want Mercury's mode checker to enforce following HTML validation rules via insts:
- An ul tag (unordered list) allows only li tags (list item) as direct children
- An li tag must have an ol tag as immediate parent

Expected result:
Compiler should report an error when creating an invalid inst.

Actual result:
Compiler aborts.

The error occurs with Mercury 20.06 as well as with rotd-2021-01-27.
Steps To Reproducemmc --make html
Additional Information$ mmc --make html
Making Mercury/int3s/html.int3
Making Mercury/ints/html.int
Making Mercury/cs/html.c
Uncaught Mercury exception:
Software Error: map.det_insert: key already present
    Key Type: parse_tree.prog_data.inst_name
    Key Value: user_inst(qualified(unqualified("html"), "non_empty_list"), [defined_inst(user_inst(qualified(unqualified("html"), "top_body_elem"), []))])
    Value Type: list.list(parse_tree.error_util.format_component)
** Error making `Mercury/cs/html.c'.
TagsNo tags attached.
Attached Files? html.m (1,907) 2021-01-29 21:40
https://bugs.mercurylang.org/file_download.php?file_id=309&type=bug

Notes
(0001129)
zs   
2021-01-30 01:34   
I am testing a fix now.

However, if I were you, I would choose a HTML representation that
encoded HTML's invariants in the type, not in the mode. It would
not have any representation for
  • tags at all. Instead, the function
    symbol for lists would look like this:

    :- type html_elem
      ---> list(html_elem, list(html_elem))
      ...

    The
  • tags would be added only when a list is unparsed.
    (Not having an explicit representation for
  • guarantees
    that this representation cannot be put anywhere it shouldn't :-)
    And storing the first element of the list separately guarantees
    that the empty list is not representable.
  • (0001130)
    zs   
    2021-01-30 01:36   
    Sorry about the formatting of the above note. I didn't realize
    that Mantis does not quote html in notes :-( Those bullets were
    originally a sequence of <, l, i, and >.
    (0001131)
    zs   
    2021-01-30 01:46   
    Fix committed 2021 Jan 30.

    Issue History
    2021-01-29 21:40dirkzNew Issue
    2021-01-29 21:40dirkzFile Added: html.m
    2021-01-30 01:25zsAssigned To => zs
    2021-01-30 01:25zsStatusnew => assigned
    2021-01-30 01:34zsNote Added: 0001129
    2021-01-30 01:36zsNote Added: 0001130
    2021-01-30 01:46zsStatusassigned => resolved
    2021-01-30 01:46zsResolutionopen => fixed
    2021-01-30 01:46zsNote Added: 0001131