Skip to content

Operator precedence in updateNested causes incorrect nested map update #99

Open

Description

@bbyalcinkaya

In updateNested, the map update operator [<-] binds tighter than
orDefault, so this rule:

rule updateNested(MAP, INDEX1, INDEX2, VALUE) => MAP[ INDEX1 <- MAP[INDEX1] orDefault .Map [INDEX2 <- VALUE] ]

is parsed as (_ [INDEX2 <- VALUE] is applied to empty map):

rule updateNested(MAP, INDEX1, INDEX2, VALUE) => MAP[ INDEX1 <- MAP[INDEX1] orDefault (.Map [INDEX2 <- VALUE]) ]
                                                                                     ^^^                    ^^^

The parsing can also be seen in the kdist-******/kontrol-node/simbolik/compiled.txt file:

rule updateNested(MAP,INDEX1,INDEX2,VALUE)
  =>`Map:update`(
        MAP,
        INDEX1,
        `Map:lookupOrDefault`(
            MAP,
            INDEX1,
            `Map:update`(
                `.Map`(.KList),
                INDEX2,
                VALUE
            )
        )
    ) 
    requires #token("true","Bool")
    ensures #token("true","Bool")

Fix: wrap the orDefault expression and add a :>Map cast:

rule updateNested(MAP, INDEX1, INDEX2, VALUE) => MAP[ INDEX1 <- {MAP[INDEX1] orDefault .Map}:>Map [INDEX2 <- VALUE] ]

The cast is needed because orDefault returns KItem, which [<-] won't accept without it.

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions