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

Unify the requirement for all interface types to have to occur in intersection types #3090

Merged
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
Loading