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

Code generator generates wrong code for `SRC I` (or it is a typechecker bug) #947

Closed RieksJ closed 3 months ago

RieksJ commented 5 years ago

Ampersand-v3.16.0 [feature/578-navbar:c3acfc3d1] can compile the following script:

CONTEXT Issue

CLASSIFY OrgUnit ISA BusinessFunction

bfIsaOrgUnit :: BusinessFunction * BusinessFunction [PROP]

ROLE ExecEngine MAINTAINS "SetConcept OrgUnit"
RULE "SetConcept OrgUnit": bfIsaOrgUnit[BusinessFunction] |- I[OrgUnit]
VIOLATION (TXT "{EX} SetConcept;BusinessFunction;OrgUnit;", SRC I)

ROLE ExecEngine MAINTAINS "Alternative SetConcept OrgUnit"
RULE "Alternative SetConcept OrgUnit": bfIsaOrgUnit[BusinessFunction] |- I[OrgUnit]
VIOLATION (TXT "{EX} SetConcept;BusinessFunction;OrgUnit;", SRC I[BusinessFunction])

ENDCONTEXT

Here is the JSON that is generated for the rule SetConcept OrgUnit:

        {
            "origin": "C:\\Ampersand\\Git\\tno-models\\GRC\\issue.adl:13:1",
            "srcConceptId": "BusinessFunction",
            "ruleAdl": "bfIsaOrgUnit [BusinessFunction] |- I[OrgUnit]",
            "pairView": [
                {
                    "expTgt": null,
                    "text": "{EX} SetConcept;BusinessFunction;OrgUnit;",
                    "srcOrTgt": null,
                    "segType": "Text",
                    "expIsIdent": null,
                    "expSQL": null,
                    "seqNr": 0
                },
                {
                    "expTgt": "OrgUnit",
                    "text": null,
                    "srcOrTgt": "Src",
                    "segType": "Exp",
                    "expIsIdent": false,
                    "expSQL": "select distinct fence0.src as src, fence1.tgt as tgt from (select \"OrgUnit\" as src, \"OrgUnit\" as tgt from \"BusinessFunction\" where \"OrgUnit\" is not null) as fence0, (select \"OrgUnit\" as src, \"OrgUnit\" as tgt from \"BusinessFunction\" where \"OrgUnit\" is not null) as fence1 where (fence0.tgt = fence1.src)",
                    "seqNr": 1
                }
            ],
            "name": "SetConcept OrgUnit",
            "meaning": "",
            "tgtConceptId": "BusinessFunction",
            "conjunctIds": [
                "conj_34"
            ],
            "message": ""
        }

Note that while SRC and TGT are both of type BusinessFunction, the SQL code is created assuming that it is OrgUnit, as it says:

select distinct fence0.src as src, fence1.tgt as tgt 
from (select \"OrgUnit\" as src, \"OrgUnit\" as tgt from \"BusinessFunction\"
          where \"OrgUnit\" is not null
) as fence0

The result of this is that while violations of the rule are properly signalled, SRC I will erroneously return a _NULL, preventing the violation from ever being fixed. Note that the alternative rule, which explicitly mentions the concept to be used, does not have this error.

So either this is a bug in the type checker, or it is a bug in the code generator.

Note: If I replace SRC I with SRC I[BusinessFunction], the error is gone (so that's the workaround).

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 5 years with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 3 months ago

This issue was closed because it has been stalled for 30 days with no activity.