Skip to content

Commit

Permalink
Merge pull request #3090 from onflow/bastian/require-contract-interfa…
Browse files Browse the repository at this point in the history
…ce-in-intersection-type
  • Loading branch information
turbolent authored Feb 14, 2024
2 parents 7536efb + dd5460e commit 58cc20f
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 240 deletions.
52 changes: 50 additions & 2 deletions migrations/statictypes/account_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestAccountTypeInTypeValueMigration(t *testing.T) {
interpreter.NewVariableSizedStaticType(nil, authAccountReferenceType),
),
},
"interface": {
"non_intersection_interface": {
storedType: interpreter.NewInterfaceStaticType(
nil,
nil,
Expand All @@ -325,6 +325,38 @@ func TestAccountTypeInTypeValueMigration(t *testing.T) {
fooBarQualifiedIdentifier,
),
),
expectedType: interpreter.NewIntersectionStaticType(
nil,
[]*interpreter.InterfaceStaticType{
interpreter.NewInterfaceStaticType(
nil,
nil,
fooBarQualifiedIdentifier,
common.NewTypeIDFromQualifiedName(
nil,
fooAddressLocation,
fooBarQualifiedIdentifier,
),
),
},
),
},
"intersection_interface": {
storedType: interpreter.NewIntersectionStaticType(
nil,
[]*interpreter.InterfaceStaticType{
interpreter.NewInterfaceStaticType(
nil,
nil,
fooBarQualifiedIdentifier,
common.NewTypeIDFromQualifiedName(
nil,
fooAddressLocation,
fooBarQualifiedIdentifier,
),
),
},
),
expectedType: nil,
},
"composite": {
Expand Down Expand Up @@ -437,7 +469,23 @@ func TestAccountTypeInTypeValueMigration(t *testing.T) {
typeValue := value.(interpreter.TypeValue)
if actualIntersectionType, ok := typeValue.Type.(*interpreter.IntersectionStaticType); ok {
expectedIntersectionType := testCase.expectedType.(*interpreter.IntersectionStaticType)
assert.True(t, actualIntersectionType.LegacyType.Equal(expectedIntersectionType.LegacyType))

if actualIntersectionType.LegacyType != nil {
assert.True(t,
actualIntersectionType.LegacyType.
Equal(expectedIntersectionType.LegacyType),
)
} else if expectedIntersectionType.LegacyType != nil {
assert.True(t,
expectedIntersectionType.LegacyType.
Equal(actualIntersectionType.LegacyType),
)
} else {
assert.Equal(t,
expectedIntersectionType.LegacyType,
actualIntersectionType.LegacyType,
)
}
}
} else {
expectedValue = interpreter.NewTypeValue(nil, testCase.storedType)
Expand Down
13 changes: 9 additions & 4 deletions migrations/statictypes/composite_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {
expectedType interpreter.StaticType
}

newCompositeType := func() interpreter.StaticType {
newCompositeType := func() *interpreter.CompositeStaticType {
return interpreter.NewCompositeStaticType(
nil,
nil,
Expand All @@ -56,7 +56,7 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {
)
}

newInterfaceType := func() interpreter.StaticType {
newInterfaceType := func() *interpreter.InterfaceStaticType {
return interpreter.NewInterfaceStaticType(
nil,
nil,
Expand All @@ -72,8 +72,13 @@ func TestCompositeAndInterfaceTypeMigration(t *testing.T) {
testCases := map[string]testCase{
// base cases
"compositeToInterface": {
storedType: newCompositeType(),
expectedType: newInterfaceType(),
storedType: newCompositeType(),
expectedType: interpreter.NewIntersectionStaticType(
nil,
[]*interpreter.InterfaceStaticType{
newInterfaceType(),
},
),
},
"interfaceToComposite": {
storedType: newInterfaceType(),
Expand Down
Loading

0 comments on commit 58cc20f

Please sign in to comment.