Skip to content

Commit

Permalink
Merge pull request #2946 from onflow/sainati/supported-entitlements-i…
Browse files Browse the repository at this point in the history
…nterface

Include interface conformances when computing the supported entitlements of an interface
  • Loading branch information
dsainati1 authored Nov 20, 2023
2 parents 7e955a3 + 17ae400 commit 787812f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
5 changes: 4 additions & 1 deletion runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5282,7 +5282,10 @@ func (t *InterfaceType) SupportedEntitlements() (set *EntitlementOrderedSet) {
})
}
})
// TODO: include inherited entitlements

t.EffectiveInterfaceConformanceSet().ForEach(func(it *InterfaceType) {
set.SetAll(it.SupportedEntitlements())
})

t.supportedEntitlements = set
return set
Expand Down
49 changes: 49 additions & 0 deletions runtime/tests/checker/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5561,6 +5561,55 @@ func TestCheckEntitlementConditions(t *testing.T) {

assert.NoError(t, err)
})

t.Run("result value inherited interface entitlement resource", func(t *testing.T) {
t.Parallel()
_, err := ParseAndCheck(t, `
entitlement X
entitlement Y
resource interface I {
access(X) view fun foo(): Bool {
return true
}
}
resource interface J: I {
access(Y) view fun bar(): Bool {
return true
}
}
fun bar(r: @{J}): @{J} {
post {
result.foo(): ""
result.bar(): ""
}
return <-r
}
`)

assert.NoError(t, err)
})

t.Run("result inherited interface method", func(t *testing.T) {
t.Parallel()
_, err := ParseAndCheck(t, `
entitlement X
entitlement Y
resource interface I {
access(X, Y) view fun foo(): Bool
}
resource interface J: I {
access(Y) view fun foo(): Bool
}
fun bar(r: @{J}): @{J} {
post {
result.foo(): ""
}
return <-r
}
`)

assert.NoError(t, err)
})
}

func TestCheckEntitledWriteAndMutateNotAllowed(t *testing.T) {
Expand Down

0 comments on commit 787812f

Please sign in to comment.