From 110bd77514aaab13d50cb9eab935e85c026b4da7 Mon Sep 17 00:00:00 2001 From: Daniel Sainati Date: Tue, 23 Jan 2024 16:00:47 -0500 Subject: [PATCH] add legacyAuthorized field to reference types --- runtime/ast/access.go | 6 +++--- runtime/ast/primitiveaccess_string.go | 6 +++--- runtime/ast/type.go | 7 ++++--- runtime/ast/type_test.go | 1 + runtime/old_parser/declaration.go | 2 +- runtime/old_parser/declaration_test.go | 10 +++++----- runtime/old_parser/type.go | 7 +++++-- runtime/old_parser/type_test.go | 6 ++++-- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/runtime/ast/access.go b/runtime/ast/access.go index f1f5d54a88..1f90a982d7 100644 --- a/runtime/ast/access.go +++ b/runtime/ast/access.go @@ -215,7 +215,7 @@ const ( AccessContract AccessAccount AccessAll - PubSettableLegacy // Deprecated + AccessPubSettableLegacy // Deprecated ) func PrimitiveAccessCount() int { @@ -254,7 +254,7 @@ func (a PrimitiveAccess) Keyword() string { return "access(account)" case AccessContract: return "access(contract)" - case PubSettableLegacy: + case AccessPubSettableLegacy: return "pub(set)" } @@ -273,7 +273,7 @@ func (a PrimitiveAccess) Description() string { return "account" case AccessContract: return "contract" - case PubSettableLegacy: + case AccessPubSettableLegacy: return "legacy public settable" } diff --git a/runtime/ast/primitiveaccess_string.go b/runtime/ast/primitiveaccess_string.go index 5f29644c90..03b4adf583 100644 --- a/runtime/ast/primitiveaccess_string.go +++ b/runtime/ast/primitiveaccess_string.go @@ -13,12 +13,12 @@ func _() { _ = x[AccessContract-2] _ = x[AccessAccount-3] _ = x[AccessAll-4] - _ = x[PubSettableLegacy-5] + _ = x[AccessPubSettableLegacy-5] } -const _PrimitiveAccess_name = "AccessNotSpecifiedAccessSelfAccessContractAccessAccountAccessAllPubSettableLegacy" +const _PrimitiveAccess_name = "AccessNotSpecifiedAccessSelfAccessContractAccessAccountAccessAllAccessPubSettableLegacy" -var _PrimitiveAccess_index = [...]uint8{0, 18, 28, 42, 55, 64, 81} +var _PrimitiveAccess_index = [...]uint8{0, 18, 28, 42, 55, 64, 87} func (i PrimitiveAccess) String() string { if i >= PrimitiveAccess(len(_PrimitiveAccess_index)-1) { diff --git a/runtime/ast/type.go b/runtime/ast/type.go index 98c10704a5..4d9f48c893 100644 --- a/runtime/ast/type.go +++ b/runtime/ast/type.go @@ -537,9 +537,10 @@ func (t *FunctionType) CheckEqual(other Type, checker TypeEqualityChecker) error // ReferenceType type ReferenceType struct { - Type Type `json:"ReferencedType"` - StartPos Position `json:"-"` - Authorization Authorization `json:"Authorization"` + Type Type `json:"ReferencedType"` + StartPos Position `json:"-"` + LegacyAuthorized bool + Authorization Authorization `json:"Authorization"` } var _ Type = &ReferenceType{} diff --git a/runtime/ast/type_test.go b/runtime/ast/type_test.go index 8269905aa4..df94807b22 100644 --- a/runtime/ast/type_test.go +++ b/runtime/ast/type_test.go @@ -1205,6 +1205,7 @@ func TestReferenceType_MarshalJSON(t *testing.T) { ` { "Type": "ReferenceType", + "LegacyAuthorized": false, "Authorization": { "ConjunctiveElements": [ { diff --git a/runtime/old_parser/declaration.go b/runtime/old_parser/declaration.go index 2edab477fb..34981591b1 100644 --- a/runtime/old_parser/declaration.go +++ b/runtime/old_parser/declaration.go @@ -273,7 +273,7 @@ func parseAccess(p *parser) (ast.PrimitiveAccess, error) { return ast.AccessNotSpecified, err } - return ast.PubSettableLegacy, nil + return ast.AccessPubSettableLegacy, nil case keywordAccess: // Skip the `access` keyword diff --git a/runtime/old_parser/declaration_test.go b/runtime/old_parser/declaration_test.go index 909c626f2f..69fdea99a5 100644 --- a/runtime/old_parser/declaration_test.go +++ b/runtime/old_parser/declaration_test.go @@ -1531,7 +1531,7 @@ func TestParseAccess(t *testing.T) { require.Empty(t, errs) utils.AssertEqualWithDiff(t, - ast.PubSettableLegacy, + ast.AccessPubSettableLegacy, result, ) }) @@ -2648,7 +2648,7 @@ func TestParseCompositeDeclaration(t *testing.T) { Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.PubSettableLegacy, + Access: ast.AccessPubSettableLegacy, VariableKind: ast.VariableKindVariable, Identifier: ast.Identifier{ Identifier: "foo", @@ -3031,7 +3031,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.PubSettableLegacy, + Access: ast.AccessPubSettableLegacy, VariableKind: ast.VariableKindVariable, Identifier: ast.Identifier{ Identifier: "foo", @@ -3233,7 +3233,7 @@ func TestParseInterfaceDeclaration(t *testing.T) { Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.PubSettableLegacy, + Access: ast.AccessPubSettableLegacy, VariableKind: ast.VariableKindVariable, Identifier: ast.Identifier{ Identifier: "foo", @@ -4423,7 +4423,7 @@ func TestParseStructure(t *testing.T) { Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.PubSettableLegacy, + Access: ast.AccessPubSettableLegacy, VariableKind: ast.VariableKindVariable, Identifier: ast.Identifier{ Identifier: "foo", diff --git a/runtime/old_parser/type.go b/runtime/old_parser/type.go index cbd55bec80..2623d4a10b 100644 --- a/runtime/old_parser/type.go +++ b/runtime/old_parser/type.go @@ -169,12 +169,15 @@ func init() { return nil, err } - return ast.NewReferenceType( + refType := ast.NewReferenceType( p.memoryGauge, nil, right, token.StartPos, - ), nil + ) + refType.LegacyAuthorized = true + + return refType, nil default: return parseNominalTypeRemainder(p, token) diff --git a/runtime/old_parser/type_test.go b/runtime/old_parser/type_test.go index f9463360e2..490d1ed35f 100644 --- a/runtime/old_parser/type_test.go +++ b/runtime/old_parser/type_test.go @@ -307,7 +307,8 @@ func TestParseReferenceType(t *testing.T) { utils.AssertEqualWithDiff(t, &ast.ReferenceType{ - Authorization: nil, + Authorization: nil, + LegacyAuthorized: true, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", @@ -2739,7 +2740,8 @@ func TestParseAuthorizedReferenceType(t *testing.T) { TypeAnnotation: &ast.TypeAnnotation{ IsResource: false, Type: &ast.ReferenceType{ - Authorization: nil, + LegacyAuthorized: true, + Authorization: nil, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "R", Pos: ast.Position{Offset: 21, Line: 2, Column: 20}},