Skip to content

Commit

Permalink
respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Oct 19, 2023
1 parent 8c53fae commit 197334d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions runtime/ast/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/turbolent/prettier"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/errors"
)

const typeSeparatorSpaceDoc = prettier.Text(": ")
Expand Down Expand Up @@ -597,6 +598,8 @@ func (t *ReferenceType) Doc() prettier.Doc {
referenceTypeMappingKeywordDoc,
authorization.EntitlementMap.Doc(),
)
default:
panic(errors.NewUnreachableError())
}
doc = append(doc, prettier.Text(")"))
doc = append(doc, prettier.Space)
Expand Down
16 changes: 7 additions & 9 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,21 +1261,19 @@ func (checker *Checker) functionType(
parameterList *ast.ParameterList,
returnTypeAnnotation *ast.TypeAnnotation,
) *FunctionType {

oldMappedAccess := checker.entitlementMappingInScope
if mapAccess, isMapAccess := access.(*EntitlementMapAccess); isMapAccess {
checker.entitlementMappingInScope = mapAccess.Type
} else {
checker.entitlementMappingInScope = nil
}
defer func() { checker.entitlementMappingInScope = oldMappedAccess }()

convertedParameters := checker.parameters(parameterList)

convertedReturnTypeAnnotation := VoidTypeAnnotation
if returnTypeAnnotation != nil {
// to allow entitlement mapping types to be used in the return annotation only of
// a mapped accessor function, we introduce a "variable" into the typing scope while
// checking the return
if mapAccess, isMapAccess := access.(*EntitlementMapAccess); isMapAccess {
checker.entitlementMappingInScope = mapAccess.Type
}
convertedReturnTypeAnnotation =
checker.ConvertTypeAnnotation(returnTypeAnnotation)
checker.entitlementMappingInScope = nil
}

return &FunctionType{
Expand Down

0 comments on commit 197334d

Please sign in to comment.