Repository navigation
fix: use old type name in Union migration type signatures for renamed types - #81
Conversation
|
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 |
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. |
|
@CharlonTank could you please add some test cases covering these changes? |
|
@supermario added two test scenarios in
While adding these, I noticed fix number 2's |
… 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>
Migrate_Union_Renamed verifies the V_old type signature uses the old type name when a Union is renamed across versions. Migrate_Nested_Dict verifies that a Dict migration nested inside another one stays a valid function argument (composed with >>, from lamdera#111). Rebased onto lamdera-next: the lambda-wrapping commit and its heuristic tweak are dropped, lamdera#111 fixed the templates at the source, and the Migrate_Nested_Dict snapshot is regenerated for its output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ee65f89 to
1a338da
Compare
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 signatureAlso in this PR: nested Dict/SeqDict pipelines
The second commit (a4605ae) fixes a separate generator bug. A key migration of a
Dict/SeqDictis emitted as a raw pipeline (Dict.toList |> List.map (…) |> Dict.fromList), which is not a function once it is passed as an argument (Tuple.mapBoth,List.map, a nestedDict.map…). It is now wrapped in(\v__ -> v__ |> …). The test scenariosMigrate_Union_RenamedandMigrate_Nested_Dictcover both fixes.#111 fixes the same pipeline problem at the source, in the
Dict/SeqDicttemplates (composition with>>, which binds no name), and also fixes the shadowed\kof nested value migrations. With #111 merged, this wrapper no longer triggers for those templates and theMigrate_Nested_Dictsnapshot needs regenerating.