fix: use old type name in Union migration type signatures for renamed types#81
fix: use old type name in Union migration type signatures for renamed types#81CharlonTank wants to merge 2 commits intolamdera:lamdera-nextfrom
Conversation
… types When a Union type is renamed between versions (e.g. MoralType in V51 → CompanyType in V52), the migration generator was using the NEW type name for the OLD version in the generated type signature: migrate_LegalEntity_CompanyType : Evergreen.V51.LegalEntity.CompanyType -> ... But CompanyType doesn't exist in V51 - it was called MoralType. The correct signature should be: migrate_LegalEntity_CompanyType : Evergreen.V51.LegalEntity.MoralType -> ... The fix threads typeNameOld through migrateUnionDefinition → migrateUnionDefinition_, mirroring how migrateAliasDefinition already correctly handles this case for type alias renames. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I built the fixed compiler locally and tested it against my project which has a Union type rename ( Before the fix: → Compilation error: After the fix: → Correct type signature, compiles fine |
When a migration for a container type parameter is a pipeline (e.g. nested SeqDict producing `SeqDict.toList |> List.map ... |> SeqDict.fromList`), it must be wrapped in a lambda before being passed as a function argument to Tuple.mapBoth, Tuple.mapFirst, List.map, etc. Without this fix, the generated code produces: Tuple.mapBoth (migrate_Email) (SeqDict.toList |> ...) which is syntactically invalid (pipeline used as a value argument). With this fix: Tuple.mapBoth (migrate_Email) (\v__ -> v__ |> SeqDict.toList |> ...)
Added second fix: nested Dict/SeqDict pipeline wrappingWhen a container type has a nested Dict/SeqDict parameter, the recursive migration produces a pipeline ( Before: Fix: In Both fixes tested locally — built the compiler and verified the generated migration compiles correctly. |
Summary
migrateUnionDefinition→migrateUnionDefinition_, mirroring howmigrateAliasDefinitionalready handles alias renamesProblem
When a Union type is renamed between versions (e.g.
MoralTypein V51 →CompanyTypein V52), the migration generator was using the new type name for the old version in the generated type signature:But
CompanyTypedoesn't exist in V51 — it was calledMoralType. This causes a compilation error in the generated migration file.Fix
The correct signature should be:
Changes in
MigrationGenerator.hs:coreTypeMigration: PasstypeNameOld(from pattern match) instead oftypeName(new name) tomigrateUnionDefinitionmigrateUnionDefinition: Renamed parameter fromtypeNameNewtotypeNameOld, derivetypeNameNewfrom the identifier'stipecomponent, and thread both tomigrateUnionDefinition_migrateUnionDefinition_: AddedtypeNameOldparameter; use it in the type signature for the old version's type reference (line 279)migrateTypeDef: PasstypeNameOldinstead oftypeNameNewtomigrateUnionDefinitionReference
The Alias case (
migrateAliasDefinition) already correctly passes and uses bothtypeNameOldandtypeNameNew— this fix brings the Union case in line with that pattern.Test plan
type MoralType = ...→type CompanyType = ...)lamdera checkand verify the generated migration file uses the old type name for the old version in the type signature