AmpersandTarski / Ampersand

Build database applications faster than anyone else, and keep your data pollution free as a bonus.
http://ampersandtarski.github.io/
GNU General Public License v3.0
40 stars 8 forks source link

Duplicate Pattern Bug #1275

Closed stefjoosten closed 2 years ago

stefjoosten commented 2 years ago

What happened

Ampersand allows duplicate patterns, such as:

CONTEXT Issue1275

   PATTERN Foo
   RELATION r[A*B]
   ENDPATTERN

   PATTERN Foo
   RELATION s[A*B]
   ENDPATTERN

ENDCONTEXT

However, the above script produces a duplicate label error and causes Pandoc to crash in the most unelegant manner:

Duplicate label: fig:Concept diagram of relations in Foo
CallStack (from HasCallStack):
  error, called at lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs:408:7 in pandoc-crossref-0.3.12.1-915mUtUhCDjEpzbcfysd1C-pandoc-crossref-internal:Text.Pandoc.CrossRef.References.Blocks
ampersand: Duplicate label: fig:Concept diagram of relations in Foo
CallStack (from HasCallStack):
  error, called at lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs:408:7 in pandoc-crossref-0.3.12.1-915mUtUhCDjEpzbcfysd1C-pandoc-crossref-internal:Text.Pandoc.CrossRef.References.Blocks

What I expected

Since the inception of Ampersand, the formal semantics of this is the union of the contents of this pattern. So the script should behave exactly the same as:

CONTEXT Issue1275

   PATTERN Foo
   RELATION r[A*B]
   RELATION s[A*B]
   ENDPATTERN

ENDCONTEXT

Version of ampersand that was used

Ampersand-v4.6.2 [51c3de2e65c540ef026925fe8547c991765a5588:refs/tags/v4.6.2]

Steps to reproduce

I ran the bug using the ampersandtarski/ampersand:v4.6.2 image.

sjo00577@BA92-VYF9TXMD9G Ampersand % docker run -it --platform=linux/amd64 -v "$(pwd)":/scripts ampersandtarski/ampersand:v4.6.2 documentation --format docx Issue1275.adl
Generating functional design document for Issue...
/scripts/images/TechnicalDataModel.gv written.
/scripts/images/TechnicalDataModel.png written.
/scripts/images/LogicalDataModel.gv written.
/scripts/images/LogicalDataModel.png written.
/scripts/images/LogicalDataModel_Grouped_By_Pattern.gv written.
/scripts/images/LogicalDataModel_Grouped_By_Pattern.png written.
/scripts/images/Classification.gv written.
/scripts/images/Classification.png written.
/scripts/images/CDConceptONE.gv written.
/scripts/images/CDConceptONE.png written.
/scripts/images/CDConceptB.gv written.
/scripts/images/CDConceptB.png written.
/scripts/images/CDConceptA.gv written.
/scripts/images/CDConceptA.png written.
/scripts/images/CDPatternFoo.gv written.
/scripts/images/CDPatternFoo.png written.
/scripts/images/CDPatternFoo.gv written.
/scripts/images/CDPatternFoo.png written.
/scripts/images/RelationsInPatternFoo.gv written.
/scripts/images/RelationsInPatternFoo.png written.
/scripts/images/RelationsInPatternFoo.gv written.
/scripts/images/RelationsInPatternFoo.png written.
Generating docx to : ./Issue1275.docx
Duplicate label: fig:Concept diagram of relations in Foo
CallStack (from HasCallStack):
  error, called at lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs:408:7 in pandoc-crossref-0.3.12.1-915mUtUhCDjEpzbcfysd1C-pandoc-crossref-internal:Text.Pandoc.CrossRef.References.Blocks
ampersand: Duplicate label: fig:Concept diagram of relations in Foo
CallStack (from HasCallStack):
  error, called at lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs:408:7 in pandoc-crossref-0.3.12.1-915mUtUhCDjEpzbcfysd1C-pandoc-crossref-internal:Text.Pandoc.CrossRef.References.Blocks
sjo00577@BA92-VYF9TXMD9G Ampersand % 
stefjoosten commented 2 years ago

The process for this bug

This bug has an easy workaround: just don't use duplicate pattern names. As a consequence, the priority of this bug cannot be 'high'. So I qualified it as 'normal'.

After fixing this bug, I suggest we add the script Issue1275.adl to the test set .../Ampersand/testing/Travis/testcases/FuncSpec/. (I have verified that this reproduces the bug in v4.6.2). For now, I'm have added the script to .../Ampersand/testing/StillUnsupported in branch issue-1275.

stefjoosten commented 2 years ago

Analysis

Two patterns that have the same name must be the same pattern. However, in the parse tree (the P-structure) different patterns in the same context can have the same name. So ADL2FSpec.hs is the place where patterns with the same name should be merged.

We need a new function to merge two Patterns and we need to use that in the construction of the Fspec. That should do the trick.

stefjoosten commented 2 years ago

@hanjoosten has solved this issue in commit 53522bfea68dbcaba541190852301f5f5682d5ca