Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Fix package interface generation for type aliases

author
Gears
committer
Louis Pilfold
date (Jul 9, 2026, 6:51 PM +0100) commit 6cbe5217 parent 6a6ee278 change-id prxyzzqu
+113 -11
+4
CHANGELOG.md
··· 501 501 - Fixed a bug where running `gleam docs build` on non-Erlang target projects 502 502 with a warm cache would not produce the module pages. 503 503 ([Matt Champagne](https://github.com/han-tyumi)) 504 + 505 + - Fixed a bug where an incorrect `package-interface.json` would be generated for 506 + certain type aliases. 507 + ([Surya Rose](https://github.com/GearsDatapacks))
+17 -11
compiler-core/src/package_interface.rs
··· 440 440 label: arg.label.clone(), 441 441 // We share the same id_map between each step so that the 442 442 // incremental ids assigned are consisten with each other 443 - type_: from_type_helper(arg.type_.as_ref(), &mut id_map), 443 + type_: from_type_with_ids(arg.type_.as_ref(), &mut id_map), 444 444 }) 445 445 .collect(), 446 446 }) ··· 456 456 .iter() 457 457 .filter(|(_, v)| v.publicity.is_public()) 458 458 { 459 + let mut id_map = IdMap::new(); 460 + 461 + for typed_parameter in alias.parameters.iter() { 462 + id_map.add_type_variable_id(typed_parameter.as_ref()); 463 + } 464 + 459 465 let _ = type_aliases.insert( 460 466 name.clone(), 461 467 TypeAliasInterface { 462 468 documentation: alias.documentation.clone(), 463 469 deprecation: DeprecationInterface::from_deprecation(&alias.deprecation), 464 470 parameters: alias.arity, 465 - alias: TypeInterface::from_type(&alias.type_), 471 + alias: from_type_with_ids(&alias.type_, &mut id_map), 466 472 }, 467 473 ); 468 474 } ··· 507 513 label: reverse_field_map 508 514 .get(&(index as u32)) 509 515 .map(|label| (*label).clone()), 510 - type_: from_type_helper(type_, &mut id_map), 516 + type_: from_type_with_ids(type_, &mut id_map), 511 517 }) 512 518 .collect(), 513 - return_: from_type_helper(return_type, &mut id_map), 519 + return_: from_type_with_ids(return_type, &mut id_map), 514 520 }, 515 521 ); 516 522 } ··· 552 558 553 559 impl TypeInterface { 554 560 fn from_type(type_: &Type) -> TypeInterface { 555 - from_type_helper(type_, &mut IdMap::new()) 561 + from_type_with_ids(type_, &mut IdMap::new()) 556 562 } 557 563 } 558 564 ··· 560 566 /// the type variables' ids that appear in the type are mapped to an incremental 561 567 /// number and consistent with each other (that is, two types variables that 562 568 /// have the same id will also have the same incremental number in the end). 563 - fn from_type_helper(type_: &Type, id_map: &mut IdMap) -> TypeInterface { 569 + fn from_type_with_ids(type_: &Type, id_map: &mut IdMap) -> TypeInterface { 564 570 match type_ { 565 571 Type::Fn { arguments, return_ } => TypeInterface::Fn { 566 572 parameters: arguments 567 573 .iter() 568 - .map(|argument| from_type_helper(argument.as_ref(), id_map)) 574 + .map(|argument| from_type_with_ids(argument.as_ref(), id_map)) 569 575 .collect(), 570 - return_: Box::new(from_type_helper(return_, id_map)), 576 + return_: Box::new(from_type_with_ids(return_, id_map)), 571 577 }, 572 578 573 579 Type::Tuple { elements } => TypeInterface::Tuple { 574 580 elements: elements 575 581 .iter() 576 - .map(|element| from_type_helper(element.as_ref(), id_map)) 582 + .map(|element| from_type_with_ids(element.as_ref(), id_map)) 577 583 .collect(), 578 584 }, 579 585 ··· 583 589 .expect("borrow type after inference") 584 590 .deref() 585 591 { 586 - TypeVar::Link { type_ } => from_type_helper(type_, id_map), 592 + TypeVar::Link { type_ } => from_type_with_ids(type_, id_map), 587 593 // Since package serialisation happens after inference there 588 594 // should be no unbound type variables. 589 595 // TODO: This branch should be `unreachable!()` but because of ··· 613 619 module: module.clone(), 614 620 parameters: arguments 615 621 .iter() 616 - .map(|argument| from_type_helper(argument.as_ref(), id_map)) 622 + .map(|argument| from_type_with_ids(argument.as_ref(), id_map)) 617 623 .collect(), 618 624 }, 619 625 }
+40
compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_alias_with_two_parameters.snap
··· 1 + --- 2 + source: compiler-core/src/package_interface/tests.rs 3 + expression: "pub type Wibble(a, b) = Result(a, b)" 4 + --- 5 + { 6 + "name": "my_package", 7 + "version": "11.10.9-1.wibble+build", 8 + "gleam-version-constraint": "1.0.0", 9 + "modules": { 10 + "my/module": { 11 + "documentation": [], 12 + "type-aliases": { 13 + "Wibble": { 14 + "documentation": null, 15 + "deprecation": null, 16 + "parameters": 2, 17 + "alias": { 18 + "kind": "named", 19 + "name": "Result", 20 + "package": "", 21 + "module": "gleam", 22 + "parameters": [ 23 + { 24 + "kind": "variable", 25 + "id": 0 26 + }, 27 + { 28 + "kind": "variable", 29 + "id": 1 30 + } 31 + ] 32 + } 33 + } 34 + }, 35 + "types": {}, 36 + "constants": {}, 37 + "functions": {} 38 + } 39 + } 40 + }
+40
compiler-core/src/package_interface/snapshots/gleam_core__package_interface__tests__type_alias_with_two_parameters_in_reverse.snap
··· 1 + --- 2 + source: compiler-core/src/package_interface/tests.rs 3 + expression: "pub type Wibble(a, b) = Result(b, a)" 4 + --- 5 + { 6 + "name": "my_package", 7 + "version": "11.10.9-1.wibble+build", 8 + "gleam-version-constraint": "1.0.0", 9 + "modules": { 10 + "my/module": { 11 + "documentation": [], 12 + "type-aliases": { 13 + "Wibble": { 14 + "documentation": null, 15 + "deprecation": null, 16 + "parameters": 2, 17 + "alias": { 18 + "kind": "named", 19 + "name": "Result", 20 + "package": "", 21 + "module": "gleam", 22 + "parameters": [ 23 + { 24 + "kind": "variable", 25 + "id": 1 26 + }, 27 + { 28 + "kind": "variable", 29 + "id": 0 30 + } 31 + ] 32 + } 33 + } 34 + }, 35 + "types": {}, 36 + "constants": {}, 37 + "functions": {} 38 + } 39 + } 40 + }
+12
compiler-core/src/package_interface/tests.rs
··· 338 338 "# 339 339 ); 340 340 } 341 + 342 + // https://github.com/gleam-lang/gleam/issues/5957 343 + #[test] 344 + pub fn type_alias_with_two_parameters() { 345 + assert_package_interface!("pub type Wibble(a, b) = Result(a, b)"); 346 + } 347 + 348 + // https://github.com/gleam-lang/gleam/issues/5957 349 + #[test] 350 + pub fn type_alias_with_two_parameters_in_reverse() { 351 + assert_package_interface!("pub type Wibble(a, b) = Result(b, a)"); 352 + }