Skip to content

Commit

Permalink
use ArrayValue/DictionaryValue SetType in migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Mar 8, 2024
1 parent abd6859 commit 0d6f45a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
12 changes: 4 additions & 8 deletions migrations/entitlements/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,9 @@ func ConvertValueToEntitlements(
return nil, nil
}

return v.NewWithType(
inter,
interpreter.EmptyLocationRange,
v.SetType(
entitledElementType.(interpreter.ArrayStaticType),
), nil
)

case *interpreter.DictionaryValue:
elementType := v.Type
Expand All @@ -259,11 +257,9 @@ func ConvertValueToEntitlements(
return nil, nil
}

return v.NewWithType(
inter,
interpreter.EmptyLocationRange,
v.SetType(
entitledElementType.(*interpreter.DictionaryStaticType),
), nil
)

case *interpreter.IDCapabilityValue:
borrowType := v.BorrowType
Expand Down
4 changes: 2 additions & 2 deletions migrations/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,15 +1151,15 @@ func (testContainerMigration) Migrate(
interpreter.PrimitiveStaticTypeAnyStruct,
)

return value.NewWithType(inter, emptyLocationRange, newType), nil
value.SetType(newType)

case *interpreter.ArrayValue:

newType := interpreter.NewVariableSizedStaticType(nil,
interpreter.PrimitiveStaticTypeAnyStruct,
)

return value.NewWithType(inter, emptyLocationRange, newType), nil
value.SetType(newType)

case *interpreter.CompositeValue:
if value.QualifiedIdentifier == "Inner" {
Expand Down
12 changes: 4 additions & 8 deletions migrations/statictypes/statictype_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,19 @@ func (m *StaticTypeMigration) Migrate(
return
}

return value.NewWithType(
inter,
interpreter.EmptyLocationRange,
value.SetType(
convertedElementType.(interpreter.ArrayStaticType),
), nil
)

case *interpreter.DictionaryValue:
convertedElementType := m.maybeConvertStaticType(value.Type, nil)
if convertedElementType == nil {
return
}

return value.NewWithType(
inter,
interpreter.EmptyLocationRange,
value.SetType(
convertedElementType.(*interpreter.DictionaryStaticType),
), nil
)
}

return
Expand Down

0 comments on commit 0d6f45a

Please sign in to comment.