Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include interface conformances when computing the supported entitlements of an interface #2946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5277,7 +5277,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} {
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading