From 92b7ffb93a5e636ad5f6f9a7286c67efa22271fb Mon Sep 17 00:00:00 2001 From: Daniel Sainati Date: Wed, 16 Aug 2023 11:44:11 -0400 Subject: [PATCH] respond to review --- runtime/convertValues_test.go | 2 +- runtime/interpreter/interpreter.go | 7 ++++--- runtime/interpreter/statictype.go | 4 ++++ runtime/tests/interpreter/entitlements_test.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go index f9ed5e2e19..cabbad6add 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -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, }, diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index f26ccf8784..17ef300dc5 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -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 { @@ -3506,7 +3507,7 @@ func referenceTypeFunction(invocation Invocation) Value { }) return entitlements }, - entitlementValues.Count(), + entitlementsCount, sema.Conjunction, ) } diff --git a/runtime/interpreter/statictype.go b/runtime/interpreter/statictype.go index 06198e0af1..fda26179f2 100644 --- a/runtime/interpreter/statictype.go +++ b/runtime/interpreter/statictype.go @@ -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 { diff --git a/runtime/tests/interpreter/entitlements_test.go b/runtime/tests/interpreter/entitlements_test.go index 69c9d1fa38..e4e6194380 100644 --- a/runtime/tests/interpreter/entitlements_test.go +++ b/runtime/tests/interpreter/entitlements_test.go @@ -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,