Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unparameterized Capability static types #3196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions migrations/statictypes/statictype_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ func (m *StaticTypeMigration) maybeConvertStaticType(staticType, parentType inte
}

case *interpreter.CapabilityStaticType:
convertedBorrowType := m.maybeConvertStaticType(staticType.BorrowType, staticType)
if convertedBorrowType != nil {
return interpreter.NewCapabilityStaticType(nil, convertedBorrowType)
borrowType := staticType.BorrowType
if borrowType != nil {
convertedBorrowType := m.maybeConvertStaticType(borrowType, staticType)
if convertedBorrowType != nil {
return interpreter.NewCapabilityStaticType(nil, convertedBorrowType)
}
}

case *interpreter.IntersectionStaticType:
Expand Down
24 changes: 22 additions & 2 deletions migrations/statictypes/statictype_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,34 @@ func TestStaticTypeMigration(t *testing.T) {

actual := migrate(t,
staticTypeMigration,
interpreter.NewTypeValue(nil, nil),
interpreter.NewUnmeteredTypeValue(nil),
// NOTE: atree value validation is disabled,
// because the type value has a nil type (which indicates an invalid or unknown type),
// and invalid unknown types are always unequal
false,
)
assert.Equal(t,
interpreter.NewTypeValue(nil, nil),
interpreter.NewUnmeteredTypeValue(nil),
actual,
)
})

t.Run("TypeValue with unparameterized Capability type", func(t *testing.T) {
t.Parallel()

staticTypeMigration := NewStaticTypeMigration()

actual := migrate(t,
staticTypeMigration,
interpreter.NewUnmeteredTypeValue(
interpreter.NewCapabilityStaticType(nil, nil),
),
true,
)
assert.Equal(t,
interpreter.NewUnmeteredTypeValue(
interpreter.NewCapabilityStaticType(nil, nil),
),
actual,
)
})
Expand Down
Loading