diff --git a/runtime/ast/access.go b/runtime/ast/access.go index d61aa75d1c..969aa58b14 100644 --- a/runtime/ast/access.go +++ b/runtime/ast/access.go @@ -54,6 +54,7 @@ func (s Separator) String() string { } type EntitlementSet interface { + Authorization Entitlements() []*NominalType Separator() Separator } @@ -64,6 +65,8 @@ type ConjunctiveEntitlementSet struct { var _ EntitlementSet = &ConjunctiveEntitlementSet{} +func (ConjunctiveEntitlementSet) isAuthorization() {} + func (s *ConjunctiveEntitlementSet) Entitlements() []*NominalType { return s.Elements } @@ -82,6 +85,8 @@ type DisjunctiveEntitlementSet struct { var _ EntitlementSet = &DisjunctiveEntitlementSet{} +func (DisjunctiveEntitlementSet) isAuthorization() {} + func (s *DisjunctiveEntitlementSet) Entitlements() []*NominalType { return s.Elements } @@ -94,6 +99,10 @@ func NewDisjunctiveEntitlementSet(entitlements []*NominalType) *DisjunctiveEntit return &DisjunctiveEntitlementSet{Elements: entitlements} } +type Authorization interface { + isAuthorization() +} + type EntitlementAccess struct { EntitlementSet EntitlementSet } @@ -121,7 +130,7 @@ func (e EntitlementAccess) entitlementsString(prefix *strings.Builder) { func (e EntitlementAccess) String() string { str := &strings.Builder{} - str.WriteString("ConjunctiveEntitlementAccess ") + str.WriteString("EntitlementAccess ") e.entitlementsString(str) return str.String() } @@ -138,33 +147,64 @@ func (e EntitlementAccess) MarshalJSON() ([]byte, error) { return json.Marshal(e.String()) } -func (e EntitlementAccess) subset(other EntitlementAccess) bool { - otherEntitlements := other.EntitlementSet.Entitlements() - otherSet := make(map[*NominalType]struct{}, len(otherEntitlements)) - for _, entitlement := range otherEntitlements { - otherSet[entitlement] = struct{}{} - } +type MappedAccess struct { + EntitlementMap *NominalType + StartPos Position +} - for _, entitlement := range e.EntitlementSet.Entitlements() { - if _, found := otherSet[entitlement]; !found { - return false - } - } +var _ Access = &MappedAccess{} + +func (*MappedAccess) isAccess() {} +func (*MappedAccess) isAuthorization() {} - return true +func (*MappedAccess) Description() string { + return "entitlement-mapped access" } -func (e EntitlementAccess) IsLessPermissiveThan(other Access) bool { - switch other := other.(type) { - case PrimitiveAccess: - return other == AccessAll - case EntitlementAccess: - return e.subset(other) - default: - return false +func NewMappedAccess( + typ *NominalType, + startPos Position, +) *MappedAccess { + return &MappedAccess{ + EntitlementMap: typ, + StartPos: startPos, } } +func (t *MappedAccess) StartPosition() Position { + return t.StartPos +} + +func (t *MappedAccess) EndPosition(memoryGauge common.MemoryGauge) Position { + return t.EntitlementMap.EndPosition(memoryGauge) +} + +func (e *MappedAccess) String() string { + var str strings.Builder + str.WriteString("mapping ") + str.WriteString(e.EntitlementMap.String()) + return str.String() +} + +func (e *MappedAccess) Keyword() string { + var str strings.Builder + str.WriteString("access(") + str.WriteString(e.String()) + str.WriteString(")") + return str.String() +} + +func (e *MappedAccess) MarshalJSON() ([]byte, error) { + type Alias MappedAccess + return json.Marshal(&struct { + *Alias + Range + }{ + Range: NewUnmeteredRangeFromPositioned(e), + Alias: (*Alias)(e), + }) +} + type PrimitiveAccess uint8 // NOTE: order indicates permissiveness: from least to most permissive! diff --git a/runtime/ast/access_test.go b/runtime/ast/access_test.go index 74526f8318..77e8fb2f44 100644 --- a/runtime/ast/access_test.go +++ b/runtime/ast/access_test.go @@ -39,6 +39,31 @@ func TestPrimitiveAccess_MarshalJSON(t *testing.T) { } } +func TestMappedAccess_MarshalJSON(t *testing.T) { + + t.Parallel() + + e := NewNominalType(nil, NewIdentifier(nil, "E", Position{Offset: 1, Line: 2, Column: 3}), []Identifier{}) + + access := NewMappedAccess(e, Position{Offset: 0, Line: 0, Column: 0}) + actual, err := json.Marshal(access) + require.NoError(t, err) + + assert.JSONEq(t, `{ + "EntitlementMap": { + "Type": "NominalType", + "Identifier": { + "Identifier": "E", + "StartPos": {"Offset": 1, "Line": 2, "Column": 3}, + "EndPos": {"Offset": 1, "Line": 2, "Column": 3} + }, + "StartPos": {"Offset": 1, "Line": 2, "Column": 3}, + "EndPos": {"Offset": 1, "Line": 2, "Column": 3} + }, + "EndPos": {"Offset": 1, "Line": 2, "Column": 3} + }`, string(actual)) +} + func TestEntitlementAccess_MarshalJSON(t *testing.T) { t.Parallel() diff --git a/runtime/ast/type.go b/runtime/ast/type.go index d69b7ec8e6..b56b6c744f 100644 --- a/runtime/ast/type.go +++ b/runtime/ast/type.go @@ -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(": ") @@ -535,22 +536,17 @@ func (t *FunctionType) CheckEqual(other Type, checker TypeEqualityChecker) error } // ReferenceType - -type Authorization struct { - EntitlementSet EntitlementSet `json:"EntitlementSet"` -} - type ReferenceType struct { - Type Type `json:"ReferencedType"` - StartPos Position `json:"-"` - Authorization *Authorization `json:"Authorization"` + Type Type `json:"ReferencedType"` + StartPos Position `json:"-"` + Authorization Authorization `json:"Authorization"` } var _ Type = &ReferenceType{} func NewReferenceType( memoryGauge common.MemoryGauge, - authorization *Authorization, + authorization Authorization, typ Type, startPos Position, ) *ReferenceType { @@ -577,26 +573,38 @@ func (t *ReferenceType) EndPosition(memoryGauge common.MemoryGauge) Position { } const referenceTypeAuthKeywordDoc = prettier.Text("auth") +const referenceTypeMappingKeywordDoc = prettier.Text("mapping ") const referenceTypeSymbolDoc = prettier.Text("&") func (t *ReferenceType) Doc() prettier.Doc { var doc prettier.Concat if t.Authorization != nil { doc = append(doc, referenceTypeAuthKeywordDoc) - entitlementSet := t.Authorization.EntitlementSet - if entitlementSet != nil && len(entitlementSet.Entitlements()) > 0 { - entitlements := entitlementSet.Entitlements() - // TODO: add indentation, improve separators. follow e.g. ParameterList.Doc() - doc = append(doc, prettier.Text("(")) - for i, entitlement := range entitlements { - doc = append(doc, entitlement.Doc()) - if i < len(entitlements)-1 { - doc = append(doc, prettier.Text(entitlementSet.Separator().String()), prettier.Space) + doc = append(doc, prettier.Text("(")) + switch authorization := t.Authorization.(type) { + case EntitlementSet: + if len(authorization.Entitlements()) > 0 { + entitlements := authorization.Entitlements() + // TODO: add indentation, improve separators. follow e.g. ParameterList.Doc() + for i, entitlement := range entitlements { + doc = append(doc, entitlement.Doc()) + if i < len(entitlements)-1 { + doc = append(doc, prettier.Text(authorization.Separator().String()), prettier.Space) + } } } - doc = append(doc, prettier.Text(")")) + case *MappedAccess: + doc = append(doc, + referenceTypeMappingKeywordDoc, + authorization.EntitlementMap.Doc(), + ) + default: + panic(errors.NewUnreachableError()) } - doc = append(doc, prettier.Space) + doc = append(doc, + prettier.Text(")"), + prettier.Space, + ) } return append( diff --git a/runtime/ast/type_test.go b/runtime/ast/type_test.go index c3b81d5e97..aaaaa2b1e6 100644 --- a/runtime/ast/type_test.go +++ b/runtime/ast/type_test.go @@ -852,12 +852,20 @@ func TestReferenceType_Doc(t *testing.T) { t.Parallel() - t.Run("auth", func(t *testing.T) { + t.Run("auth with entitlement", func(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{}, + Authorization: &ConjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", + }, + }, + }, + }, Type: &NominalType{ Identifier: Identifier{ Identifier: "T", @@ -868,6 +876,9 @@ func TestReferenceType_Doc(t *testing.T) { assert.Equal(t, prettier.Concat{ prettier.Text("auth"), + prettier.Text("("), + prettier.Text("X"), + prettier.Text(")"), prettier.Space, prettier.Text("&"), prettier.Text("T"), @@ -876,19 +887,15 @@ func TestReferenceType_Doc(t *testing.T) { ) }) - t.Run("auth with entitlement", func(t *testing.T) { + t.Run("auth with mapping", func(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &ConjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, - }, + Authorization: &MappedAccess{ + EntitlementMap: &NominalType{ + Identifier: Identifier{ + Identifier: "X", }, }, }, @@ -903,6 +910,7 @@ func TestReferenceType_Doc(t *testing.T) { prettier.Concat{ prettier.Text("auth"), prettier.Text("("), + prettier.Text("mapping "), prettier.Text("X"), prettier.Text(")"), prettier.Space, @@ -918,18 +926,16 @@ func TestReferenceType_Doc(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &ConjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, + Authorization: &ConjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", }, - { - Identifier: Identifier{ - Identifier: "Y", - }, + }, + { + Identifier: Identifier{ + Identifier: "Y", }, }, }, @@ -963,18 +969,16 @@ func TestReferenceType_Doc(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &DisjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, + Authorization: &DisjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", }, - { - Identifier: Identifier{ - Identifier: "Y", - }, + }, + { + Identifier: Identifier{ + Identifier: "Y", }, }, }, @@ -1029,12 +1033,20 @@ func TestReferenceType_String(t *testing.T) { t.Parallel() - t.Run("auth", func(t *testing.T) { + t.Run("auth with entitlement", func(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{}, + Authorization: &ConjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", + }, + }, + }, + }, Type: &NominalType{ Identifier: Identifier{ Identifier: "T", @@ -1043,24 +1055,20 @@ func TestReferenceType_String(t *testing.T) { } assert.Equal(t, - "auth &T", + "auth(X) &T", ty.String(), ) }) - t.Run("auth with entitlement", func(t *testing.T) { + t.Run("auth with mapping", func(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &ConjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, - }, + Authorization: &MappedAccess{ + EntitlementMap: &NominalType{ + Identifier: Identifier{ + Identifier: "X", }, }, }, @@ -1072,7 +1080,7 @@ func TestReferenceType_String(t *testing.T) { } assert.Equal(t, - "auth(X) &T", + "auth(mapping X) &T", ty.String(), ) }) @@ -1082,18 +1090,16 @@ func TestReferenceType_String(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &ConjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, + Authorization: &ConjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", }, - { - Identifier: Identifier{ - Identifier: "Y", - }, + }, + { + Identifier: Identifier{ + Identifier: "Y", }, }, }, @@ -1116,18 +1122,16 @@ func TestReferenceType_String(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &DisjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, + Authorization: &DisjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", }, - { - Identifier: Identifier{ - Identifier: "Y", - }, + }, + { + Identifier: Identifier{ + Identifier: "Y", }, }, }, @@ -1170,18 +1174,16 @@ func TestReferenceType_MarshalJSON(t *testing.T) { t.Parallel() ty := &ReferenceType{ - Authorization: &Authorization{ - EntitlementSet: &ConjunctiveEntitlementSet{ - Elements: []*NominalType{ - { - Identifier: Identifier{ - Identifier: "X", - }, + Authorization: &ConjunctiveEntitlementSet{ + Elements: []*NominalType{ + { + Identifier: Identifier{ + Identifier: "X", }, - { - Identifier: Identifier{ - Identifier: "Y", - }, + }, + { + Identifier: Identifier{ + Identifier: "Y", }, }, }, @@ -1204,30 +1206,28 @@ func TestReferenceType_MarshalJSON(t *testing.T) { { "Type": "ReferenceType", "Authorization": { - "EntitlementSet": { - "ConjunctiveElements": [ - { - "Type": "NominalType", - "Identifier": { - "Identifier": "X", - "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, - "EndPos": {"Offset": 0, "Line": 0, "Column": 0} - }, + "ConjunctiveElements": [ + { + "Type": "NominalType", + "Identifier": { + "Identifier": "X", "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, "EndPos": {"Offset": 0, "Line": 0, "Column": 0} - }, - { - "Type": "NominalType", - "Identifier": { - "Identifier": "Y", - "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, - "EndPos": {"Offset": 0, "Line": 0, "Column": 0} - }, + }, + "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, + "EndPos": {"Offset": 0, "Line": 0, "Column": 0} + }, + { + "Type": "NominalType", + "Identifier": { + "Identifier": "Y", "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, "EndPos": {"Offset": 0, "Line": 0, "Column": 0} - } - ] - } + }, + "StartPos": {"Offset": 0, "Line": 0, "Column": 0}, + "EndPos": {"Offset": 0, "Line": 0, "Column": 0} + } + ] }, "ReferencedType": { "Type": "NominalType", diff --git a/runtime/entitlements_test.go b/runtime/entitlements_test.go index b9cfb672a3..048d179412 100644 --- a/runtime/entitlements_test.go +++ b/runtime/entitlements_test.go @@ -235,7 +235,7 @@ func TestRuntimeAccountEntitlementAttachmentMap(t *testing.T) { access(all) resource R {} - access(M) attachment A for R { + access(mapping M) attachment A for R { access(Y) fun foo() {} } @@ -1172,7 +1172,7 @@ func TestRuntimeImportedEntitlementMapInclude(t *testing.T) { } access(all) struct S { - access(M) fun performMap(): auth(M) &Int { + access(mapping M) fun performMap(): auth(mapping M) &Int { return &1 } } diff --git a/runtime/parser/declaration.go b/runtime/parser/declaration.go index 2bec673b50..9f067dd9f0 100644 --- a/runtime/parser/declaration.go +++ b/runtime/parser/declaration.go @@ -400,6 +400,20 @@ func parseAccess(p *parser) (ast.Access, error) { // Skip the keyword p.nextSemanticToken() + case KeywordMapping: + + keywordPos := p.current.StartPos + // Skip the keyword + p.nextSemanticToken() + + entitlementMapName, err := parseNominalType(p, lowestBindingPower) + if err != nil { + return ast.AccessNotSpecified, err + } + access = ast.NewMappedAccess(entitlementMapName, keywordPos) + + p.skipSpaceAndComments() + default: entitlements, err := parseEntitlementList(p) if err != nil { diff --git a/runtime/parser/declaration_test.go b/runtime/parser/declaration_test.go index 7a36b96683..d0f00041cb 100644 --- a/runtime/parser/declaration_test.go +++ b/runtime/parser/declaration_test.go @@ -2011,6 +2011,48 @@ func TestParseAccess(t *testing.T) { ) }) + t.Run("access, entitlement map", func(t *testing.T) { + + t.Parallel() + + result, errs := parse("access ( mapping foo )") + require.Empty(t, errs) + + utils.AssertEqualWithDiff(t, + &ast.MappedAccess{ + EntitlementMap: &ast.NominalType{ + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{Offset: 17, Line: 1, Column: 17}, + }, + }, + StartPos: ast.Position{Offset: 9, Line: 1, Column: 9}, + }, + result, + ) + }) + + t.Run("access, entitlement map no name", func(t *testing.T) { + + t.Parallel() + + result, errs := parse("access ( mapping )") + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "unexpected token in type: ')'", + Pos: ast.Position{Offset: 18, Line: 1, Column: 18}, + }, + }, + errs, + ) + + utils.AssertEqualWithDiff(t, + ast.AccessNotSpecified, + result, + ) + }) + } func TestParseImportDeclaration(t *testing.T) { diff --git a/runtime/parser/type.go b/runtime/parser/type.go index 74cd207ce8..feace57cbc 100644 --- a/runtime/parser/type.go +++ b/runtime/parser/type.go @@ -921,11 +921,30 @@ func defineIdentifierTypes() { return nil, err } - entitlements, err := parseEntitlementList(p) - if err != nil { - return nil, err + p.skipSpaceAndComments() + + keyword := p.currentTokenSource() + switch string(keyword) { + case KeywordMapping: + keywordPos := p.current.StartPos + // Skip the keyword + p.nextSemanticToken() + + entitlementMapName, err := parseNominalType(p, lowestBindingPower) + if err != nil { + return nil, err + } + authorization = ast.NewMappedAccess(entitlementMapName, keywordPos) + p.skipSpaceAndComments() + + default: + entitlements, err := parseEntitlementList(p) + if err != nil { + return nil, err + } + authorization = entitlements } - authorization.EntitlementSet = entitlements + _, err = p.mustOne(lexer.TokenParenClose) if err != nil { return nil, err @@ -944,7 +963,7 @@ func defineIdentifierTypes() { return ast.NewReferenceType( p.memoryGauge, - &authorization, + authorization, right, token.StartPos, ), nil diff --git a/runtime/parser/type_test.go b/runtime/parser/type_test.go index 34e059e52f..4ea45cc415 100644 --- a/runtime/parser/type_test.go +++ b/runtime/parser/type_test.go @@ -322,14 +322,12 @@ func TestParseReferenceType(t *testing.T) { utils.AssertEqualWithDiff(t, &ast.ReferenceType{ - Authorization: &ast.Authorization{ - EntitlementSet: &ast.ConjunctiveEntitlementSet{ - Elements: []*ast.NominalType{ - { - Identifier: ast.Identifier{ - Identifier: "X", - Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, - }, + Authorization: &ast.ConjunctiveEntitlementSet{ + Elements: []*ast.NominalType{ + { + Identifier: ast.Identifier{ + Identifier: "X", + Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, }, }, }, @@ -355,20 +353,18 @@ func TestParseReferenceType(t *testing.T) { utils.AssertEqualWithDiff(t, &ast.ReferenceType{ - Authorization: &ast.Authorization{ - EntitlementSet: &ast.ConjunctiveEntitlementSet{ - Elements: []*ast.NominalType{ - { - Identifier: ast.Identifier{ - Identifier: "X", - Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, - }, + Authorization: &ast.ConjunctiveEntitlementSet{ + Elements: []*ast.NominalType{ + { + Identifier: ast.Identifier{ + Identifier: "X", + Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, }, - { - Identifier: ast.Identifier{ - Identifier: "Y", - Pos: ast.Position{Line: 1, Column: 8, Offset: 8}, - }, + }, + { + Identifier: ast.Identifier{ + Identifier: "Y", + Pos: ast.Position{Line: 1, Column: 8, Offset: 8}, }, }, }, @@ -394,20 +390,18 @@ func TestParseReferenceType(t *testing.T) { utils.AssertEqualWithDiff(t, &ast.ReferenceType{ - Authorization: &ast.Authorization{ - EntitlementSet: &ast.DisjunctiveEntitlementSet{ - Elements: []*ast.NominalType{ - { - Identifier: ast.Identifier{ - Identifier: "X", - Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, - }, + Authorization: &ast.DisjunctiveEntitlementSet{ + Elements: []*ast.NominalType{ + { + Identifier: ast.Identifier{ + Identifier: "X", + Pos: ast.Position{Line: 1, Column: 5, Offset: 5}, }, - { - Identifier: ast.Identifier{ - Identifier: "Y", - Pos: ast.Position{Line: 1, Column: 8, Offset: 8}, - }, + }, + { + Identifier: ast.Identifier{ + Identifier: "Y", + Pos: ast.Position{Line: 1, Column: 8, Offset: 8}, }, }, }, @@ -472,6 +466,52 @@ func TestParseReferenceType(t *testing.T) { errs, ) }) + + t.Run("authorized, map", func(t *testing.T) { + + t.Parallel() + + result, errs := testParseType("auth ( mapping X ) & Int") + require.Empty(t, errs) + + utils.AssertEqualWithDiff(t, + &ast.ReferenceType{ + Authorization: &ast.MappedAccess{ + EntitlementMap: &ast.NominalType{ + Identifier: ast.Identifier{ + Identifier: "X", + Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + }, + }, + StartPos: ast.Position{Line: 1, Column: 7, Offset: 7}, + }, + Type: &ast.NominalType{ + Identifier: ast.Identifier{ + Identifier: "Int", + Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + }, + }, + StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + }, + result, + ) + }) + + t.Run("authorized, map no name", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseType("auth( mapping ) &Int") + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "unexpected token in type: ')'", + Pos: ast.Position{Offset: 15, Line: 1, Column: 15}, + }, + }, + errs, + ) + }) } func TestParseOptionalReferenceType(t *testing.T) { diff --git a/runtime/sema/checker.go b/runtime/sema/checker.go index 3c1656d14f..bbec00d501 100644 --- a/runtime/sema/checker.go +++ b/runtime/sema/checker.go @@ -1026,9 +1026,14 @@ func (checker *Checker) convertReferenceType(t *ast.ReferenceType) Type { var ty Type if t.Authorization != nil { - access = checker.accessFromAstAccess(ast.EntitlementAccess{EntitlementSet: t.Authorization.EntitlementSet}) - switch mapAccess := access.(type) { - case *EntitlementMapAccess: + switch auth := t.Authorization.(type) { + case ast.EntitlementSet: + access = checker.accessFromAstAccess(ast.EntitlementAccess{EntitlementSet: auth}) + case *ast.MappedAccess: + access = checker.accessFromAstAccess(auth) + } + + if mapAccess, isMapAccess := access.(*EntitlementMapAccess); isMapAccess { // mapped auth types are only allowed in the annotations of composite fields and accessor functions if checker.entitlementMappingInScope == nil || !checker.entitlementMappingInScope.Equal(mapAccess.Type) { checker.report(&InvalidMappedAuthorizationOutsideOfFieldError{ @@ -1934,6 +1939,31 @@ func (checker *Checker) accessFromAstAccess(access ast.Access) (result Access) { case ast.PrimitiveAccess: return PrimitiveAccess(access) + case *ast.MappedAccess: + semaAccess, hasAccess := checker.Elaboration.GetSemanticAccess(access) + if hasAccess { + return semaAccess + } + defer func() { + checker.Elaboration.SetSemanticAccess(access, result) + }() + + switch nominalType := checker.convertNominalType(access.EntitlementMap).(type) { + case *EntitlementMapType: + result = NewEntitlementMapAccess(nominalType) + default: + if nominalType != InvalidType { + checker.report( + &InvalidEntitlementMappingTypeError{ + Type: nominalType, + Pos: access.EntitlementMap.Identifier.Pos, + }, + ) + } + result = PrimitiveAccess(ast.AccessNotSpecified) + } + return + case ast.EntitlementAccess: semaAccess, hasAccess := checker.Elaboration.GetSemanticAccess(access) if hasAccess { @@ -1944,62 +1974,43 @@ func (checker *Checker) accessFromAstAccess(access ast.Access) (result Access) { }() astEntitlements := access.EntitlementSet.Entitlements() - nominalType := checker.convertNominalType(astEntitlements[0]) - switch nominalType := nominalType.(type) { - case *EntitlementType: - semanticEntitlements := make([]*EntitlementType, 0, len(astEntitlements)) - semanticEntitlements = append(semanticEntitlements, nominalType) + semanticEntitlements := make([]*EntitlementType, 0, len(astEntitlements)) - for _, entitlement := range astEntitlements[1:] { - nominalType := checker.convertNominalType(entitlement) - entitlementType, ok := nominalType.(*EntitlementType) - if !ok { - // don't duplicate errors when the type here is invalid, as this will have triggered an error before - if nominalType != InvalidType { + for _, entitlement := range astEntitlements { + nominalType := checker.convertNominalType(entitlement) + entitlementType, ok := nominalType.(*EntitlementType) + if !ok { + // don't duplicate errors when the type here is invalid, as this will have triggered an error before + if nominalType != InvalidType { + if _, isMap := nominalType.(*EntitlementMapType); isMap { + checker.report( + &MappingAccessMissingKeywordError{ + Type: nominalType, + Range: ast.NewRangeFromPositioned(checker.memoryGauge, entitlement), + }, + ) + } else { checker.report( &InvalidNonEntitlementAccessError{ Range: ast.NewRangeFromPositioned(checker.memoryGauge, entitlement), }, ) } - result = PrimitiveAccess(ast.AccessNotSpecified) - return } - semanticEntitlements = append(semanticEntitlements, entitlementType) - } - if access.EntitlementSet.Separator() == ast.Conjunction { - result = NewEntitlementSetAccess(semanticEntitlements, Conjunction) - return - } - result = NewEntitlementSetAccess(semanticEntitlements, Disjunction) - return - case *EntitlementMapType: - // 0-length entitlement lists are rejected by the parser - if len(astEntitlements) != 1 { - checker.report( - &InvalidMultipleMappedEntitlementError{ - Pos: astEntitlements[1].Identifier.Pos, - }, - ) result = PrimitiveAccess(ast.AccessNotSpecified) return } - result = NewEntitlementMapAccess(nominalType) - return - default: - // don't duplicate errors when the type here is invalid, as this will have triggered an error before - if nominalType != InvalidType { - checker.report( - &InvalidNonEntitlementAccessError{ - Range: ast.NewRangeFromPositioned(checker.memoryGauge, astEntitlements[0]), - }, - ) - } - result = PrimitiveAccess(ast.AccessNotSpecified) + semanticEntitlements = append(semanticEntitlements, entitlementType) + } + if access.EntitlementSet.Separator() == ast.Conjunction { + result = NewEntitlementSetAccess(semanticEntitlements, Conjunction) return } + result = NewEntitlementSetAccess(semanticEntitlements, Disjunction) + return } + panic(errors.NewUnreachableError()) } diff --git a/runtime/sema/errors.go b/runtime/sema/errors.go index 5d31b1d552..e3cc446446 100644 --- a/runtime/sema/errors.go +++ b/runtime/sema/errors.go @@ -4190,27 +4190,32 @@ func (e *InvalidEntitlementAccessError) EndPosition(common.MemoryGauge) ast.Posi return e.Pos } -// InvalidMultipleMappedEntitlementError -type InvalidMultipleMappedEntitlementError struct { - Pos ast.Position +// InvalidEntitlementMappingTypeError +type InvalidEntitlementMappingTypeError struct { + Type Type + Pos ast.Position } -var _ SemanticError = &InvalidMultipleMappedEntitlementError{} -var _ errors.UserError = &InvalidMultipleMappedEntitlementError{} +var _ SemanticError = &InvalidEntitlementMappingTypeError{} +var _ errors.UserError = &InvalidEntitlementMappingTypeError{} + +func (*InvalidEntitlementMappingTypeError) isSemanticError() {} -func (*InvalidMultipleMappedEntitlementError) isSemanticError() {} +func (*InvalidEntitlementMappingTypeError) IsUserError() {} -func (*InvalidMultipleMappedEntitlementError) IsUserError() {} +func (e *InvalidEntitlementMappingTypeError) Error() string { + return fmt.Sprintf("`%s` is not an entitlement map type", e.Type.QualifiedString()) +} -func (e *InvalidMultipleMappedEntitlementError) Error() string { - return "entitlement mappings cannot be used as part of an entitlement set" +func (e *InvalidEntitlementMappingTypeError) SecondaryError() string { + return "consider removing the `mapping` keyword" } -func (e *InvalidMultipleMappedEntitlementError) StartPosition() ast.Position { +func (e *InvalidEntitlementMappingTypeError) StartPosition() ast.Position { return e.Pos } -func (e *InvalidMultipleMappedEntitlementError) EndPosition(common.MemoryGauge) ast.Position { +func (e *InvalidEntitlementMappingTypeError) EndPosition(common.MemoryGauge) ast.Position { return e.Pos } @@ -4279,6 +4284,27 @@ func (e *InvalidNonEntitlementAccessError) Error() string { return "only entitlements may be used in access modifiers" } +// MappingAccessMissingKeywordError +type MappingAccessMissingKeywordError struct { + Type Type + ast.Range +} + +var _ SemanticError = &MappingAccessMissingKeywordError{} +var _ errors.UserError = &MappingAccessMissingKeywordError{} + +func (*MappingAccessMissingKeywordError) isSemanticError() {} + +func (*MappingAccessMissingKeywordError) IsUserError() {} + +func (e *MappingAccessMissingKeywordError) Error() string { + return "entitlement mapping access modifiers require the `mapping` keyword preceding the name of the map" +} + +func (e *MappingAccessMissingKeywordError) SecondaryError() string { + return fmt.Sprintf("replace `%s` with `mapping %s`", e.Type.QualifiedString(), e.Type.QualifiedString()) +} + // DirectEntitlementAnnotationError type DirectEntitlementAnnotationError struct { ast.Range diff --git a/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index 4e22cca971..3889a7c38e 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -3871,8 +3871,8 @@ func TestCheckAttachmentsExternalMutation(t *testing.T) { Mutate -> Insert } - access(M) attachment A for R { - access(Identity) let x: [String] + access(mapping M) attachment A for R { + access(mapping Identity) let x: [String] init() { self.x = ["x"] } @@ -3955,8 +3955,8 @@ func TestCheckAttachmentsExternalMutation(t *testing.T) { xRef.append("y") } } - access(M) attachment A for R { - access(Identity) let x: [String] + access(mapping M) attachment A for R { + access(mapping Identity) let x: [String] init() { self.x = ["x"] } @@ -4524,7 +4524,7 @@ func TestCheckAttachmentForEachAttachment(t *testing.T) { } } resource R {} - access(M) attachment A for R { + access(mapping M) attachment A for R { access(F) fun foo() {} } access(all) fun foo(s: @R) { diff --git a/runtime/tests/checker/entitlements_test.go b/runtime/tests/checker/entitlements_test.go index 9a7bc9d4c5..2b6ea3360a 100644 --- a/runtime/tests/checker/entitlements_test.go +++ b/runtime/tests/checker/entitlements_test.go @@ -628,7 +628,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) let foo: auth(M) &String + access(mapping M) let foo: auth(mapping M) &String } `) @@ -642,7 +642,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) let foo: auth(M) &String? + access(mapping M) let foo: auth(mapping M) &String? } `) @@ -656,7 +656,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) let foo: String + access(mapping M) let foo: String } `) @@ -672,7 +672,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) let foo: &String + access(mapping M) let foo: &String } `) @@ -688,7 +688,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) let foo: [String] + access(mapping M) let foo: [String] } `) @@ -704,7 +704,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping N {} struct interface S { - access(M) let foo: auth(N) &String + access(mapping M) let foo: auth(mapping N) &String } `) @@ -723,7 +723,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement N struct interface S { - access(M) let foo: auth(N) &String + access(mapping M) let foo: auth(N) &String } `) @@ -739,7 +739,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) fun foo() + access(mapping M) fun foo() } `) @@ -755,7 +755,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} contract interface S { - access(M) fun foo(): auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int } `) @@ -770,8 +770,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } `) @@ -788,7 +788,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) fun foo(): auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int } `) @@ -804,7 +804,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) fun foo(): auth(X) &Int + access(mapping M) fun foo(): auth(X) &Int } `) @@ -822,7 +822,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(X) fun foo(): auth(M) &Int + access(X) fun foo(): auth(mapping M) &Int } `) @@ -838,7 +838,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct interface S { - access(M) fun foo(): auth(M) &Int? + access(mapping M) fun foo(): auth(mapping M) &Int? } `) @@ -852,8 +852,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping M {} struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } `) @@ -870,8 +870,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { entitlement mapping N {} struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(N) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping N) &Int } } `) @@ -898,7 +898,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &1 as auth(Y, Z) &Int } } @@ -925,8 +925,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { var x: [auth(Y) &Int] = [] struct S { - access(M) fun foo(): auth(M) &Int { - let r = &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + let r = &1 as auth(mapping M) &Int x[0] = r return r } @@ -951,8 +951,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { - let x = &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + let x = &1 as auth(mapping M) &Int // cannot cast, because M may be access(all) let y: auth(F) &Int = x return y @@ -983,16 +983,16 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { var x: [AnyStruct] = [] struct S { - access(M) fun foo(cond: Bool): auth(M) &Int { + access(mapping M) fun foo(cond: Bool): auth(mapping M) &Int { if(cond) { let r = x[0] - if let ref = x as? auth(M) &Int { + if let ref = x as? auth(mapping M) &Int { return ref } else { - return &2 as auth(M) &Int + return &2 as auth(mapping M) &Int } } else { - let r = &3 as auth(M) &Int + let r = &3 as auth(mapping M) &Int x.append(r) return r } @@ -1023,8 +1023,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) fun foo(cond: Bool): auth(M) &T { - let x = &T() as auth(M) &T + access(mapping M) fun foo(cond: Bool): auth(mapping M) &T { + let x = &T() as auth(mapping M) &T if let y = x as? auth(Y) &T { y.foo() } @@ -1054,8 +1054,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) fun foo(cond: Bool): auth(M) &T { - let x = &T() as auth(M) &T + access(mapping M) fun foo(cond: Bool): auth(mapping M) &T { + let x = &T() as auth(mapping M) &T x.foo() return x } @@ -1110,8 +1110,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) let t: auth(M) &T - access(M) fun foo(cond: Bool): auth(M) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping M) fun foo(cond: Bool): auth(mapping M) &Int { // success because we have self is fully entitled to the domain of M return self.t.getRef() } @@ -1146,8 +1146,8 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct S { - access(M) let t: auth(M) &T - access(M) fun foo(cond: Bool): auth(M) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping M) fun foo(cond: Bool): auth(mapping M) &Int { // invalid bc we have no Z entitlement return self.t.getRef() } @@ -1210,13 +1210,13 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T + access(mapping M) let t: auth(mapping M) &T access(X) fun foo(cond: Bool): auth(Z) &Int { return self.t.getRef() } @@ -1252,14 +1252,14 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(cond: Bool): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(cond: Bool): auth(mapping NM) &Int { return self.t.getRef() } @@ -1290,13 +1290,13 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { X -> Q } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(cond: Bool): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(cond: Bool): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -1339,13 +1339,13 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { X -> Z } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(cond: Bool): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(cond: Bool): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -1377,13 +1377,13 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { A -> B } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(cond: Bool): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(cond: Bool): auth(mapping NM) &Int { // the B entitlement doesn't pass through the mapping N return self.t.getRef() } @@ -1429,13 +1429,13 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { A -> B } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(cond: Bool): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(cond: Bool): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -1452,7 +1452,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} struct interface S { - access(M) fun foo(): [auth(M) &Int] + access(mapping M) fun foo(): [auth(mapping M) &Int] } `) @@ -1474,7 +1474,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { G -> H } struct interface S { - access(M) fun foo(_ arg: auth(M) &Int): auth(M) &Int + access(mapping M) fun foo(_ arg: auth(mapping M) &Int): auth(mapping M) &Int } fun foo(s: auth(E) &{S}) { @@ -1485,32 +1485,6 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { assert.NoError(t, err) }) - t.Run("accessor function with invalid mapped ref arg", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement E - entitlement F - entitlement G - entitlement H - entitlement mapping M { - E -> F - G -> H - } - struct interface S { - access(M) fun foo(_ arg: auth(M) &Int): auth(M) &Int - } - - fun foo(s: auth(E) &{S}) { - s.foo(&1 as auth(H) &Int) - } - `) - - errs := RequireCheckerErrors(t, err, 1) - - require.IsType(t, &sema.TypeMismatchError{}, errs[0]) - }) - t.Run("accessor function with full mapped ref arg", func(t *testing.T) { t.Parallel() @@ -1524,7 +1498,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { G -> H } struct interface S { - access(M) fun foo(_ arg: auth(M) &Int): auth(M) &Int + access(mapping M) fun foo(_ arg: auth(mapping M) &Int): auth(mapping M) &Int } fun foo(s: {S}) { @@ -1535,52 +1509,34 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { assert.NoError(t, err) }) - t.Run("multiple mappings conjunction", func(t *testing.T) { + t.Run("invalid mapping", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - entitlement mapping M {} - entitlement mapping N {} - resource interface R { - access(M, N) let foo: String - } - `) - - errs := RequireCheckerErrors(t, err, 1) - - require.IsType(t, &sema.InvalidMultipleMappedEntitlementError{}, errs[0]) - }) - - t.Run("multiple mappings conjunction with regular", func(t *testing.T) { - t.Parallel() - - _, err := ParseAndCheck(t, ` - entitlement mapping M {} - entitlement N + entitlement M resource interface R { - access(M, N) let foo: String + access(mapping M) let foo: String } `) errs := RequireCheckerErrors(t, err, 1) - require.IsType(t, &sema.InvalidMultipleMappedEntitlementError{}, errs[0]) + require.IsType(t, &sema.InvalidEntitlementMappingTypeError{}, errs[0]) }) - t.Run("multiple mappings disjunction", func(t *testing.T) { + t.Run("mapping without keyword", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - entitlement mapping M {} entitlement mapping N {} resource interface R { - access(M | N) let foo: String + access(N) let foo: String } `) errs := RequireCheckerErrors(t, err, 1) - require.IsType(t, &sema.InvalidMultipleMappedEntitlementError{}, errs[0]) + require.IsType(t, &sema.MappingAccessMissingKeywordError{}, errs[0]) }) t.Run("multiple mappings disjunction with regular", func(t *testing.T) { @@ -1596,7 +1552,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { errs := RequireCheckerErrors(t, err, 1) - require.IsType(t, &sema.InvalidNonEntitlementAccessError{}, errs[0]) + require.IsType(t, &sema.MappingAccessMissingKeywordError{}, errs[0]) }) t.Run("valid in contract", func(t *testing.T) { @@ -1606,7 +1562,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { contract C { entitlement mapping M {} struct interface S { - access(M) let foo: auth(M) &String + access(mapping M) let foo: auth(mapping M) &String } } `) @@ -1621,7 +1577,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { contract interface C { entitlement mapping M {} struct interface S { - access(M) let foo: auth(M) &String + access(mapping M) let foo: auth(mapping M) &String } } `) @@ -1636,11 +1592,11 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { contract C { entitlement mapping M {} struct interface S { - access(M) let foo: auth(M) &String + access(mapping M) let foo: auth(mapping M) &String } } resource interface R { - access(C.M) let bar: auth(C.M) &String + access(mapping C.M) let bar: auth(mapping C.M) &String } `) @@ -1653,7 +1609,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: [auth(M) &Int] + access(mapping M) let foo: [auth(mapping M) &Int] } `) @@ -1789,7 +1745,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - let x: auth(M) &Int = 3 + let x: auth(mapping M) &Int = 3 `) errs := RequireCheckerErrors(t, err, 2) @@ -1803,7 +1759,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - fun foo(x: auth(M) &Int) { + fun foo(x: auth(mapping M) &Int) { } `) @@ -1818,7 +1774,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - fun foo(): auth(M) &Int {} + fun foo(): auth(mapping M) &Int {} `) errs := RequireCheckerErrors(t, err, 2) @@ -1832,7 +1788,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - let x = &1 as auth(M) &Int + let x = &1 as auth(mapping M) &Int `) errs := RequireCheckerErrors(t, err, 1) @@ -1846,7 +1802,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} let x = &1 as &Int - let y = x as? auth(M) &Int + let y = x as? auth(mapping M) &Int `) errs := RequireCheckerErrors(t, err, 1) @@ -1859,7 +1815,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - fun foo(x: Capability) {} + fun foo(x: Capability) {} `) errs := RequireCheckerErrors(t, err, 1) @@ -1874,7 +1830,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { entitlement mapping M {} fun test(storage: auth(Storage) &Account.Storage) { - let x = storage.borrow(from: /storage/foo) + let x = storage.borrow(from: /storage/foo) } `) @@ -1889,7 +1845,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} let x = &1 as &Int - let y = x as auth(M) &Int + let y = x as auth(mapping M) &Int `) errs := RequireCheckerErrors(t, err, 1) @@ -1903,7 +1859,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: Capability + access(mapping M) let foo: Capability } `) @@ -1918,7 +1874,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: (auth(M) &Int)? + access(mapping M) let foo: (auth(mapping M) &Int)? } `) @@ -1932,7 +1888,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: fun(auth(M) &Int): auth(M) &Int + access(mapping M) let foo: fun(auth(mapping M) &Int): auth(mapping M) &Int } `) @@ -1947,7 +1903,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: fun((auth(M) &Int?)) + access(mapping M) let foo: fun((auth(mapping M) &Int?)) } `) @@ -1966,7 +1922,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { E -> F } struct interface S { - access(E) var x: auth(M) &String + access(E) var x: auth(mapping M) &String } `) @@ -1985,7 +1941,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { E -> F } struct interface S { - access(E) var x: fun(auth(M) &String): Int + access(E) var x: fun(auth(mapping M) &String): Int } `) @@ -2004,7 +1960,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { E -> F } struct interface S { - access(M) var x: auth(E) &String + access(mapping M) var x: auth(E) &String } `) @@ -2026,7 +1982,7 @@ func TestCheckInvalidEntitlementMappingAuth(t *testing.T) { E -> F } struct interface S { - access(M) var x: auth(N) &String + access(mapping M) var x: auth(mapping N) &String } `) @@ -2046,7 +2002,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - access(M) var x: String = "" + access(mapping M) var x: String = "" `) errs := RequireCheckerErrors(t, err, 1) @@ -2060,7 +2016,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: Int + access(mapping M) let foo: Int } `) @@ -2075,7 +2031,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource interface R { - access(M) let foo: Int? + access(mapping M) let foo: Int? } `) @@ -2089,7 +2045,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} - access(M) fun foo() {} + access(mapping M) fun foo() {} `) errs := RequireCheckerErrors(t, err, 1) @@ -2103,7 +2059,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} contract C { - access(M) fun foo() {} + access(mapping M) fun foo() {} } `) @@ -2118,7 +2074,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} contract interface C { - access(M) fun foo() + access(mapping M) fun foo() } `) @@ -2133,7 +2089,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} resource I { - access(M) event Foo() + access(mapping M) event Foo() } `) @@ -2149,7 +2105,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping M {} enum X: UInt8 { - access(M) case red + access(mapping M) case red } `) @@ -2163,7 +2119,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` resource R { - access(M) fun foo() {} + access(mapping M) fun foo() {} } `) @@ -2177,7 +2133,7 @@ func TestCheckInvalidEntitlementMappingAccess(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface S { - access(M) let foo: String + access(mapping M) let foo: String } `) @@ -2373,10 +2329,10 @@ func TestCheckEntitlementInheritance(t *testing.T) { X -> Y } struct interface I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String } struct S: I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String init() { self.x = &"foo" as auth(Y) &String } @@ -2396,10 +2352,10 @@ func TestCheckEntitlementInheritance(t *testing.T) { X -> Y } struct interface I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String } struct interface S: I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String } `) @@ -2417,10 +2373,10 @@ func TestCheckEntitlementInheritance(t *testing.T) { X -> Y } struct interface I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String } struct S: I { - access(N) let x: auth(N) &String + access(mapping N) let x: auth(mapping N) &String init() { self.x = &"foo" as auth(Y) &String } @@ -2443,10 +2399,10 @@ func TestCheckEntitlementInheritance(t *testing.T) { X -> Y } struct interface I { - access(M) let x: auth(M) &String + access(mapping M) let x: auth(mapping M) &String } struct interface S: I { - access(N) let x: auth(N) &String + access(mapping N) let x: auth(mapping N) &String } `) @@ -2638,7 +2594,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { access(E, F) var x: auth(E, F) &String } struct S: I { - access(M) var x: auth(M) &String + access(mapping M) var x: auth(mapping M) &String init() { self.x = &"foo" as auth(F) &String @@ -2661,7 +2617,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { E -> F } struct interface I { - access(M) var x: auth(M) &String + access(mapping M) var x: auth(mapping M) &String } struct S: I { access(E, F) var x: auth(E, F) &String @@ -2690,7 +2646,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { access(E | F) var x: auth(E | F) &String } struct S: I { - access(M) var x: auth(M) &String + access(mapping M) var x: auth(mapping M) &String init() { self.x = &"foo" as auth(F) &String @@ -2713,7 +2669,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { E -> F } struct interface I { - access(M) var x: auth(M) &String + access(mapping M) var x: auth(mapping M) &String } struct S: I { access(E | F) var x: auth(E | F) &String @@ -3024,8 +2980,8 @@ func TestCheckEntitlementInheritance(t *testing.T) { } entitlement G struct interface I { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } struct S: I {} @@ -3053,12 +3009,12 @@ func TestCheckEntitlementInheritance(t *testing.T) { G -> E } struct interface I { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } struct S {} - access(N) attachment A for S: I {} + access(mapping N) attachment A for S: I {} fun test() { let s = attach A() to S() let ref = &s as auth(G) &S @@ -3083,13 +3039,13 @@ func TestCheckEntitlementInheritance(t *testing.T) { G -> E } struct interface I { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } struct interface I2: I {} struct S {} - access(N) attachment A for S: I2 {} + access(mapping N) attachment A for S: I2 {} fun test() { let s = attach A() to S() let ref = &s as auth(G) &S @@ -3114,8 +3070,8 @@ func TestCheckEntitlementInheritance(t *testing.T) { G -> E } struct interface I { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } struct S {} @@ -3633,7 +3589,7 @@ func TestCheckAttachmentEntitlementAccessAnnotation(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping E {} - access(E) attachment A for AnyStruct {} + access(mapping E) attachment A for AnyStruct {} `) assert.NoError(t, err) @@ -3667,7 +3623,7 @@ func TestCheckAttachmentEntitlementAccessAnnotation(t *testing.T) { entitlement mapping E { X -> Y } - access(E) attachment A for AnyStruct { + access(mapping E) attachment A for AnyStruct { access(Y) fun foo() {} } } @@ -3858,7 +3814,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { access(Y) fun foo() {} } struct interface S { - access(M) let x: auth(M) &Q + access(mapping M) let x: auth(mapping M) &Q } fun foo(s: auth(X) &{S}) { s.x.foo() @@ -3881,7 +3837,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { access(Y) fun foo() {} } struct interface S { - access(M) let x: auth(M) &Q + access(mapping M) let x: auth(mapping M) &Q } fun foo(s: auth(X) &{S}?) { s?.x?.foo() @@ -3902,7 +3858,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { } struct Q {} struct interface S { - access(M) let x: auth(M) &Q + access(mapping M) let x: auth(mapping M) &Q } fun foo(s: auth(X) &{S}?): auth(Y) &Q? { return s?.x @@ -3925,7 +3881,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access (mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -3953,7 +3909,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -4003,8 +3959,8 @@ func TestCheckEntitlementMapAccess(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } fun foo(s: auth(X) &S?): auth(X, Y) &Int? { @@ -4039,7 +3995,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { E -> F } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(X | E) &{S}) { let x: auth(Y | F) &Int = ref.x @@ -4071,7 +4027,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Y } struct interface S { - access(M) let x: auth(M) &Int? + access(mapping M) let x: auth(mapping M) &Int? } fun foo(ref: auth(X) &{S}) { let x: auth(Y) &Int? = ref.x @@ -4091,7 +4047,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Y } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(X) &{S}) { let x: auth(X) &Int = ref.x @@ -4126,7 +4082,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { A -> B } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A) &{S}) { let x: auth(Y) &Int = ref.x @@ -4161,7 +4117,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { A -> B } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A | X) &{S}) { let x: auth(B | Y) &Int = ref.x @@ -4186,7 +4142,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { A -> B } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A | X) &{S}) { let x = ref.x @@ -4213,7 +4169,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { A -> Y } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A | X) &{S}) { let x = ref.x @@ -4240,7 +4196,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(X) &{S}) { let x: auth(Y, Z) &Int = ref.x @@ -4263,7 +4219,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(D) &{S}) { let x1: auth(D) &Int = ref.x @@ -4297,7 +4253,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(X) &{S}) { let x: auth(Z) &Int = ref.x @@ -4322,7 +4278,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { B -> C } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref1: auth(A) &{S}, ref2: auth(B) &{S}) { let x1: auth(C) &Int = ref1.x @@ -4350,7 +4306,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A, X) &{S}) { let x: auth(B, C, Y, Z) &Int = ref.x @@ -4379,7 +4335,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: auth(A, X) &{S}) { let upRef = ref as auth(A) &{S} @@ -4412,7 +4368,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Y } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: &{S}) { let x: &Int = ref.x @@ -4432,7 +4388,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Y } struct interface S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int } fun foo(ref: &{S}) { let x: auth(Y) &Int = ref.x @@ -4466,7 +4422,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int init() { self.x = &1 as auth(Y, Z) &Int } @@ -4490,7 +4446,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) var x: auth(M) &Int + access(mapping M) var x: auth(mapping M) &Int init() { self.x = &1 as auth(Y, Z) &Int } @@ -4515,7 +4471,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) var x: auth(M) &Int + access(mapping M) var x: auth(mapping M) &Int init() { self.x = &1 as auth(Y, Z) &Int } @@ -4541,7 +4497,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Y } struct S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int init() { self.x = &1 as &Int } @@ -4568,7 +4524,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int init() { self.x = &1 as auth(Y) &Int } @@ -4595,7 +4551,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int init() { self.x = (&1 as auth(Y) &Int) as auth(Y | Z) &Int } @@ -4622,7 +4578,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { X -> Z } struct S { - access(M) let x: auth(M) &Int + access(mapping M) let x: auth(mapping M) &Int init() { self.x = 1 } @@ -4652,7 +4608,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y) fun entitled() { let a: auth(Y) &A = self let b: &S = base @@ -4698,7 +4654,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { require entitlement X access(all) fun unentitled() { let b: &S = base @@ -4733,7 +4689,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(all) fun unentitled() { let b: &S = base } @@ -4767,7 +4723,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { require entitlement X require entitlement Y access(all) fun unentitled() { @@ -4797,7 +4753,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { struct S { access(E, X) fun foo() {} } - access(M) attachment A for S { + access(mapping M) attachment A for S { access(F, Y) fun entitled() { let a: auth(F, Y) &A = self } @@ -4834,7 +4790,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(E) fun entitled() {} } `) @@ -4862,7 +4818,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y | E | Z) fun entitled() {} } `) @@ -4888,7 +4844,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { E -> F } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(F, X, E) fun entitled() {} } `) @@ -4921,8 +4877,8 @@ func TestCheckAttachmentEntitlements(t *testing.T) { struct S { access(Y) fun foo() {} } - access(M) attachment A for S { - access(M) let x: auth(M) &S + access(mapping M) attachment A for S { + access(mapping M) let x: auth(mapping M) &S init() { self.x = &S() as auth(Y) &S } @@ -5013,7 +4969,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y, Z) fun foo() {} } let s = attach A() to S() @@ -5036,7 +4992,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { } struct interface I {} struct S: I {} - access(M) attachment A for I { + access(mapping M) attachment A for I { access(Y, Z) fun foo() {} } let s: {I} = attach A() to S() @@ -5061,7 +5017,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { struct S { access(X, E) fun foo() {} } - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y, F) fun foo() {} } let s = attach A() to S() @@ -5109,7 +5065,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { X -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y) fun foo() {} } let s = attach A() to S() @@ -5222,7 +5178,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { access(X, E) fun foo() {} } - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y, Z, F, G) fun foo() {} } @@ -5664,7 +5620,7 @@ func TestCheckEntitledWriteAndMutateNotAllowed(t *testing.T) { X -> Y } struct S { - access(M) var x: auth(M) &Int + access(mapping M) var x: auth(mapping M) &Int init() { self.x = &1 as auth(Y) &Int } @@ -5689,7 +5645,7 @@ func TestCheckEntitledWriteAndMutateNotAllowed(t *testing.T) { X -> Y } struct S { - access(M) var x: auth(M) &Int + access(mapping M) var x: auth(mapping M) &Int init() { self.x = &1 as auth(Y) &Int } @@ -6223,9 +6179,9 @@ func TestCheckIdentityMapping(t *testing.T) { _, err := ParseAndCheck(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -6258,9 +6214,9 @@ func TestCheckIdentityMapping(t *testing.T) { _, err := ParseAndCheck(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -6286,9 +6242,9 @@ func TestCheckIdentityMapping(t *testing.T) { _, err := ParseAndCheck(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -6314,9 +6270,9 @@ func TestCheckIdentityMapping(t *testing.T) { _, err := ParseAndCheck(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -6355,21 +6311,21 @@ func TestCheckIdentityMapping(t *testing.T) { struct Y { // Reference - access(Identity) var x1: auth(Identity) &X + access(mapping Identity) var x1: auth(mapping Identity) &X // Optional reference - access(Identity) var x2: auth(Identity) &X? + access(mapping Identity) var x2: auth(mapping Identity) &X? // Function returning a reference - access(Identity) fun getX(): auth(Identity) &X { + access(mapping Identity) fun getX(): auth(mapping Identity) &X { let x = X() - return &x as auth(Identity) &X + return &x as auth(mapping Identity) &X } // Function returning an optional reference - access(Identity) fun getOptionalX(): auth(Identity) &X? { + access(mapping Identity) fun getOptionalX(): auth(mapping Identity) &X? { let x: X? = X() - return &x as auth(Identity) &X? + return &x as auth(mapping Identity) &X? } init() { @@ -6415,7 +6371,7 @@ func TestCheckIdentityMapping(t *testing.T) { struct Y { - access(Identity) let fn: (fun (): X) + access(mapping Identity) let fn: (fun (): X) init() { self.fn = fun(): X { @@ -6454,7 +6410,7 @@ func TestCheckIdentityMapping(t *testing.T) { struct Y { - access(Identity) let fn: auth(Identity) &(fun (): X)? + access(mapping Identity) let fn: auth(mapping Identity) &(fun (): X)? init() { self.fn = nil @@ -6669,7 +6625,7 @@ func TestCheckIdentityIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6695,7 +6651,7 @@ func TestCheckIdentityIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6728,7 +6684,7 @@ func TestCheckIdentityIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6762,7 +6718,7 @@ func TestCheckIdentityIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6800,7 +6756,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6836,7 +6792,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6875,7 +6831,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6912,7 +6868,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6954,7 +6910,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -6992,7 +6948,7 @@ func TestCheckGeneralIncludedMaps(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -7360,7 +7316,7 @@ func TestCheckEntitlementOptionalChaining(t *testing.T) { } struct S { - access(E) let foo: auth(E) &Int + access(mapping E) let foo: auth(mapping E) &Int init() { self.foo = &0 as auth(Y) &Int } @@ -7390,7 +7346,7 @@ func TestCheckEntitlementMissingInMap(t *testing.T) { NonExistingEntitlement -> X } access(all) struct S { - access(M) var foo: auth(M) &Int + access(mapping M) var foo: auth(mapping M) &Int init() { self.foo = &3 as auth(X) &Int var selfRef = &self as auth(X) &S @@ -7415,7 +7371,7 @@ func TestCheckEntitlementMissingInMap(t *testing.T) { Int -> X } access(all) struct S { - access(M) var foo: auth(M) &Int + access(mapping M) var foo: auth(mapping M) &Int init() { self.foo = &3 as auth(X) &Int var selfRef = &self as auth(X) &S @@ -7444,7 +7400,7 @@ func TestInterpretMappingEscalation(t *testing.T) { Y -> Remove } struct S { - access(M) var member: auth(M) &[Int]? + access(mapping M) var member: auth(mapping M) &[Int]? init() { self.member = nil; } @@ -7477,7 +7433,7 @@ func TestInterpretMappingEscalation(t *testing.T) { Y -> Remove } struct S { - access(M) var member: auth(M) &[Int]? + access(mapping M) var member: auth(mapping M) &[Int]? init() { self.member = nil; } @@ -7523,7 +7479,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let arr: [auth(MyMap) &InnerObj] + access(mapping MyMap) let arr: [auth(mapping MyMap) &InnerObj] init() { self.arr = [&InnerObj()] } @@ -7558,7 +7514,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let arr: [auth(MyMap) &InnerObj] + access(mapping MyMap) let arr: [auth(mapping MyMap) &InnerObj] init() { self.arr = [&InnerObj()] } @@ -7594,7 +7550,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) fun getArr(): [auth(MyMap) &InnerObj] { + access(mapping MyMap) fun getArr(): [auth(mapping MyMap) &InnerObj] { return [&InnerObj()] } } @@ -7625,7 +7581,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let arr: [auth(MyMap) &InnerObj] + access(mapping MyMap) let arr: [auth(mapping MyMap) &InnerObj] init() { self.arr = [&InnerObj()] } @@ -7633,7 +7589,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { struct TranslatorStruct { access(self) var carrier: &Carrier; - access(MyMap) fun translate(): auth(MyMap) &InnerObj { + access(mapping MyMap) fun translate(): auth(mapping MyMap) &InnerObj { return self.carrier.arr[0] // type mismatch } init(_ carrier: &Carrier) { @@ -7665,7 +7621,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let dict: {String: auth(MyMap) &InnerObj} + access(mapping MyMap) let dict: {String: auth(mapping MyMap) &InnerObj} init() { self.dict = {"": &InnerObj()} } @@ -7700,7 +7656,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let dict: {String: auth(MyMap) &InnerObj} + access(mapping MyMap) let dict: {String: auth(mapping MyMap) &InnerObj} init() { self.dict = {"": &InnerObj()} } @@ -7736,7 +7692,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) fun getDict(): {String: auth(MyMap) &InnerObj} { + access(mapping MyMap) fun getDict(): {String: auth(mapping MyMap) &InnerObj} { return {"": &InnerObj()} } } @@ -7767,7 +7723,7 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let fnArr: [fun(auth(MyMap) &InnerObj): auth(MyMap) &InnerObj] + access(mapping MyMap) let fnArr: [fun(auth(mapping MyMap) &InnerObj): auth(mapping MyMap) &InnerObj] init() { let innerObj = &InnerObj() as auth(Inner1, Inner2) &InnerObj self.fnArr = [fun(_ x: &InnerObj): auth(Inner1, Inner2) &InnerObj { @@ -7815,9 +7771,9 @@ func TestCheckEntitlementMappingComplexFields(t *testing.T) { } struct FuncGenerator { - access(MyMap) fun generate(): auth(MyMap) &Int? { + access(mapping MyMap) fun generate(): auth(mapping MyMap) &Int? { // cannot declare lambda with mapped entitlement - fun innerFunc(_ param: auth(MyMap) &InnerObj): Int { + fun innerFunc(_ param: auth(mapping MyMap) &InnerObj): Int { return 123; } var f = innerFunc; // will fail if we're called via a reference diff --git a/runtime/tests/checker/member_test.go b/runtime/tests/checker/member_test.go index 92715d07c9..ea2b592220 100644 --- a/runtime/tests/checker/member_test.go +++ b/runtime/tests/checker/member_test.go @@ -764,7 +764,7 @@ func TestCheckMemberAccess(t *testing.T) { } struct S { - access(M) let foo: [String] + access(mapping M) let foo: [String] init() { self.foo = [] } @@ -796,13 +796,13 @@ func TestCheckMemberAccess(t *testing.T) { C -> D } struct Foo { - access(FooMapping) let bars: [Bar] + access(mapping FooMapping) let bars: [Bar] init() { self.bars = [Bar()] } } struct Bar { - access(BarMapping) let baz: Baz + access(mapping BarMapping) let baz: Baz init() { self.baz = Baz() } @@ -843,14 +843,14 @@ func TestCheckMemberAccess(t *testing.T) { } struct Foo { - access(FooMapping) let bars: [Bar] + access(mapping FooMapping) let bars: [Bar] init() { self.bars = [Bar()] } } struct Bar { - access(BarMapping) let baz: Baz + access(mapping BarMapping) let baz: Baz init() { self.baz = Baz() } diff --git a/runtime/tests/interpreter/attachments_test.go b/runtime/tests/interpreter/attachments_test.go index 6d6d4ccc92..616a73e92c 100644 --- a/runtime/tests/interpreter/attachments_test.go +++ b/runtime/tests/interpreter/attachments_test.go @@ -1956,13 +1956,13 @@ func TestInterpretForEachAttachment(t *testing.T) { E -> Y } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(F) fun foo(_ x: Int): Int { return 7 + x } } - access(N) attachment B for S { + access(mapping N) attachment B for S { access(Y) fun foo(): Int { return 10 } } - access(O) attachment C for S { + access(mapping O) attachment C for S { access(Y) fun foo(_ x: Int): Int { return 8 + x } } fun test(): Int { diff --git a/runtime/tests/interpreter/entitlements_test.go b/runtime/tests/interpreter/entitlements_test.go index ad6dfeda60..616faece8d 100644 --- a/runtime/tests/interpreter/entitlements_test.go +++ b/runtime/tests/interpreter/entitlements_test.go @@ -1124,7 +1124,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { X -> Y } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &2 as auth(Y) &Int } @@ -1174,7 +1174,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -1225,7 +1225,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -1275,7 +1275,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -1325,7 +1325,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y, Q) &Int } @@ -1374,7 +1374,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - access(M) let foo: auth(M) &Int + access(mapping M) let foo: auth(mapping M) &Int init() { self.foo = &3 as auth(F, Y) &Int } @@ -1427,8 +1427,8 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { } struct S { access(self) let myFoo: Int - access(M) fun foo(): auth(M) &Int { - return &self.myFoo as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &self.myFoo as auth(mapping M) &Int } init() { self.myFoo = 3 @@ -1484,8 +1484,8 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Y } struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } fun test(): auth(Y) &Int { @@ -1522,7 +1522,7 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Y } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &1 as auth(Y, Z) &Int } } @@ -1557,8 +1557,8 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Z } struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } fun test(): auth(Y, Z) &Int { @@ -1596,8 +1596,8 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Z } struct S { - access(M) fun foo(): auth(M) &Int { - return &1 as auth(M) &Int + access(mapping M) fun foo(): auth(mapping M) &Int { + return &1 as auth(mapping M) &Int } } fun test(): auth(Y, Z) &Int { @@ -1636,10 +1636,10 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int? { + access(mapping M) fun foo(): auth(mapping M) &Int? { let ref = &1 as auth(F) &Int // here M is substituted for F, so this works - if let r = ref as? auth(M) &Int { + if let r = ref as? auth(mapping M) &Int { return r } else { return nil @@ -1682,10 +1682,10 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int? { + access(mapping M) fun foo(): auth(mapping M) &Int? { let ref = &1 as auth(F) &Int // here M is substituted for Y, so this fails - if let r = ref as? auth(M) &Int { + if let r = ref as? auth(mapping M) &Int { return r } else { return nil @@ -1724,9 +1724,9 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int? { + access(mapping M) fun foo(): auth(mapping M) &Int? { let x = [&1 as auth(Y) &Int] - let y = x as! [auth(M) &Int] + let y = x as! [auth(mapping M) &Int] return y[0] } } @@ -1761,9 +1761,9 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int? { + access(mapping M) fun foo(): auth(mapping M) &Int? { let x = [&1 as auth(Y) &Int] - let y = x as! [auth(M) &Int] + let y = x as! [auth(mapping M) &Int] return y[0] } } @@ -1794,9 +1794,9 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { E -> F } struct S { - access(M) fun foo(): auth(M) &Int? { + access(mapping M) fun foo(): auth(mapping M) &Int? { let ref = &1 as auth(F) &Int - if let r = ref as? auth(M) &Int { + if let r = ref as? auth(mapping M) &Int { return r } else { return nil @@ -1837,8 +1837,8 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { } } struct S { - access(M) let t: auth(M) &T - access(M) fun foo(): auth(M) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping M) fun foo(): auth(mapping M) &Int { // success because we have self is fully entitled to the domain of M return self.t.getRef() } @@ -1882,12 +1882,12 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { Y -> Z } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T + access(mapping M) let t: auth(mapping M) &T access(X) fun foo(): auth(Z) &Int { return self.t.getRef() } @@ -1934,13 +1934,13 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Z } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -1989,13 +1989,13 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { X -> Z } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -2046,13 +2046,13 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { A -> B } struct T { - access(N) fun getRef(): auth(N) &Int { - return &1 as auth(N) &Int + access(mapping N) fun getRef(): auth(mapping N) &Int { + return &1 as auth(mapping N) &Int } } struct S { - access(M) let t: auth(M) &T - access(NM) fun foo(): auth(NM) &Int { + access(mapping M) let t: auth(mapping M) &T + access(mapping NM) fun foo(): auth(mapping NM) &Int { return self.t.getRef() } init() { @@ -2093,7 +2093,7 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { G -> H } struct S { - access(M) fun foo(_ arg: auth(M) &Int): auth(M) &Int { + access(mapping M) fun foo(_ arg: auth(mapping M) &Int): auth(mapping M) &Int { return arg } } @@ -2132,7 +2132,7 @@ func TestInterpretEntitlementMappingAccessors(t *testing.T) { G -> H } struct S { - access(M) fun foo(_ arg: auth(M) &Int): auth(M) &Int { + access(mapping M) fun foo(_ arg: auth(mapping M) &Int): auth(mapping M) &Int { return arg } } @@ -2174,7 +2174,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S {} + access(mapping M) attachment A for S {} fun test(): auth(Y, Z) &A { let s = attach A() to S() return s[A]! @@ -2208,7 +2208,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y | Z) fun entitled(): auth(Y, Z) &A { return self } @@ -2246,7 +2246,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(Y | Z) fun entitled(): &S { return base } @@ -2279,7 +2279,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { X -> Z } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { require entitlement X access(Y | Z) fun entitled(): auth(X) &S { return base @@ -2324,7 +2324,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } struct S {} - access(M) attachment A for S {} + access(mapping M) attachment A for S {} fun test(): auth(F, G) &A { let s = attach A() to S() let ref = &s as auth(E) &S @@ -2365,7 +2365,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(F | Z) fun entitled(): auth(Y, Z, F, G) &A { return self } @@ -2410,7 +2410,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(F | Z) fun entitled(): &S { return base } @@ -2450,7 +2450,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } struct S {} - access(M) attachment A for S { + access(mapping M) attachment A for S { require entitlement E access(F | Z) fun entitled(): auth(E) &S { return base @@ -2497,7 +2497,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { } struct S: I {} struct interface I {} - access(M) attachment A for I {} + access(mapping M) attachment A for I {} fun test(): auth(F, G) &A { let s = attach A() to S() let ref = &s as auth(E) &{I} @@ -2540,7 +2540,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } resource R {} - access(M) attachment A for R {} + access(mapping M) attachment A for R {} fun test(): auth(F, G) &A { let r <- attach A() to <-create R() account.storage.save(<-r, to: /storage/foo) @@ -2586,7 +2586,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } resource R {} - access(M) attachment A for R { + access(mapping M) attachment A for R { access(F | Z) fun entitled(): auth(F, G, Y, Z) &A { return self } @@ -2636,7 +2636,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } resource R {} - access(M) attachment A for R { + access(mapping M) attachment A for R { require entitlement X access(F | Z) fun entitled(): auth(X) &R { return base @@ -2685,7 +2685,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { E -> G } resource R {} - access(M) attachment A for R { + access(mapping M) attachment A for R { require entitlement E require entitlement X init() { @@ -2728,7 +2728,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { } struct S {} struct T {} - access(M) attachment A for S { + access(mapping M) attachment A for S { access(self) let t: T init(t: T) { self.t = t @@ -2737,7 +2737,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { return &self.t as auth(Z) &T } } - access(N) attachment B for T {} + access(mapping N) attachment B for T {} fun test(): auth(X) &B { let s = attach A(t: attach B() to T()) to S() let ref = &s as auth(X) &S @@ -2772,9 +2772,9 @@ func TestInterpretEntitledAttachments(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &AnyStruct { + access(mapping M) fun foo(): auth(mapping M) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(M) &AnyStruct + return &a as auth(mapping M) &AnyStruct } } @@ -2940,9 +2940,9 @@ func TestInterpretIdentityMapping(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -2963,9 +2963,9 @@ func TestInterpretIdentityMapping(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -2988,9 +2988,9 @@ func TestInterpretIdentityMapping(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -3017,9 +3017,9 @@ func TestInterpretIdentityMapping(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S { - access(Identity) fun foo(): auth(Identity) &AnyStruct { + access(mapping Identity) fun foo(): auth(mapping Identity) &AnyStruct { let a: AnyStruct = "hello" - return &a as auth(Identity) &AnyStruct + return &a as auth(mapping Identity) &AnyStruct } } @@ -3057,21 +3057,21 @@ func TestInterpretIdentityMapping(t *testing.T) { struct Y { // Reference - access(Identity) var x1: auth(Identity) &X + access(mapping Identity) var x1: auth(mapping Identity) &X // Optional reference - access(Identity) var x2: auth(Identity) &X? + access(mapping Identity) var x2: auth(mapping Identity) &X? // Function returning a reference - access(Identity) fun getX(): auth(Identity) &X { + access(mapping Identity) fun getX(): auth(mapping Identity) &X { let x = X() - return &x as auth(Identity) &X + return &x as auth(mapping Identity) &X } // Function returning an optional reference - access(Identity) fun getOptionalX(): auth(Identity) &X? { + access(mapping Identity) fun getOptionalX(): auth(mapping Identity) &X? { let x: X? = X() - return &x as auth(Identity) &X? + return &x as auth(mapping Identity) &X? } init() { @@ -3116,7 +3116,7 @@ func TestInterpretMappingInclude(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -3160,7 +3160,7 @@ func TestInterpretMappingInclude(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -3210,7 +3210,7 @@ func TestInterpretMappingInclude(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -3266,7 +3266,7 @@ func TestInterpretMappingInclude(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -3326,7 +3326,7 @@ func TestInterpretMappingInclude(t *testing.T) { } struct S { - access(M) fun foo(): auth(M) &Int { + access(mapping M) fun foo(): auth(mapping M) &Int { return &3 } } @@ -3381,7 +3381,7 @@ func TestInterpretEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let arr: [auth(MyMap) &InnerObj] + access(mapping MyMap) let arr: [auth(mapping MyMap) &InnerObj] init() { self.arr = [&InnerObj()] } @@ -3424,7 +3424,7 @@ func TestInterpretEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let dict: {String: auth(MyMap) &InnerObj} + access(mapping MyMap) let dict: {String: auth(mapping MyMap) &InnerObj} init() { self.dict = {"": &InnerObj()} } @@ -3467,7 +3467,7 @@ func TestInterpretEntitlementMappingComplexFields(t *testing.T) { } struct Carrier{ - access(MyMap) let fnArr: [fun(auth(MyMap) &InnerObj): auth(MyMap) &InnerObj] + access(mapping MyMap) let fnArr: [fun(auth(mapping MyMap) &InnerObj): auth(mapping MyMap) &InnerObj] init() { let innerObj = &InnerObj() as auth(Inner1, Inner2) &InnerObj self.fnArr = [fun(_ x: &InnerObj): auth(Inner1, Inner2) &InnerObj { diff --git a/runtime/tests/interpreter/member_test.go b/runtime/tests/interpreter/member_test.go index 26cb33b692..faa66d7174 100644 --- a/runtime/tests/interpreter/member_test.go +++ b/runtime/tests/interpreter/member_test.go @@ -1075,7 +1075,7 @@ func TestInterpretMemberAccess(t *testing.T) { } struct S { - access(M) let foo: [String] + access(mapping M) let foo: [String] init() { self.foo = [] }