Skip to content

Commit

Permalink
respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Aug 16, 2023
1 parent 62e3c61 commit 92b7ffb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ func TestImportRuntimeType(t *testing.T) {
Authorization: interpreter.NewEntitlementSetAuthorization(
nil,
func() []common.TypeID { return []common.TypeID{"E", "F"} },
1,
2,
sema.Disjunction),
ReferencedType: interpreter.PrimitiveStaticTypeInt,
},
Expand Down
7 changes: 4 additions & 3 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3482,12 +3482,13 @@ func referenceTypeFunction(invocation Invocation) Value {

var authorization Authorization = UnauthorizedAccess
errInIteration := false
entitlementsCount := entitlementValues.Count()

if entitlementValues.Count() > 0 {
if entitlementsCount > 0 {
authorization = NewEntitlementSetAuthorization(
invocation.Interpreter,
func() []common.TypeID {
var entitlements []common.TypeID = make([]common.TypeID, 0, entitlementValues.Count())
entitlements := make([]common.TypeID, 0, entitlementsCount)
entitlementValues.Iterate(invocation.Interpreter, func(element Value) (resume bool) {
entitlementString, isString := element.(*StringValue)
if !isString {
Expand All @@ -3506,7 +3507,7 @@ func referenceTypeFunction(invocation Invocation) Value {
})
return entitlements
},
entitlementValues.Count(),
entitlementsCount,
sema.Conjunction,
)
}
Expand Down
4 changes: 4 additions & 0 deletions runtime/interpreter/statictype.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ func NewEntitlementSetAuthorization(
})

entitlementList := entitlementListConstructor()
if len(entitlementList) > entitlementListSize {
// it should not be possible to reach this point unless something is implemented wrong
panic(errors.NewUnreachableError())
}

entitlements := orderedmap.New[sema.TypeIDOrderedSet](len(entitlementList))
for _, entitlement := range entitlementList {
Expand Down
2 changes: 1 addition & 1 deletion runtime/tests/interpreter/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func TestInterpretEntitledReferenceCasting(t *testing.T) {
interpreter.NewEntitlementSetAuthorization(
nil,
func() []common.TypeID { return []common.TypeID{"S.test.X", "S.test.Y"} },
1,
2,
sema.Conjunction,
),
interpreter.PrimitiveStaticTypeInt,
Expand Down

0 comments on commit 92b7ffb

Please sign in to comment.