Skip to content

Commit

Permalink
Change type id to new type id in PortableRegistry::retain(). (#204)
Browse files Browse the repository at this point in the history
* fix retain

* bump version

* add test, fix ui tests
  • Loading branch information
tadeohepperle committed Mar 22, 2024
1 parent 1e02764 commit 938790b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.11.1] - 2024-03-22

- Fix a bug in the `PortableRegistry::retain()` method, where a type's id field was not adjusted to the new position of the type in the retained `Vec`.

## [2.11.0] - 2024-03-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "2.11.0"
version = "2.11.1"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
rust-version = "1.60.0"
Expand Down
5 changes: 5 additions & 0 deletions src/portable.rs
Expand Up @@ -181,6 +181,7 @@ impl PortableRegistry {

// Retain this type, having updated any inner IDs:
let new_id = new_types.len() as u32;
ty.id = new_id;
new_types.push(ty);
retained_mappings.insert(id, new_id);
new_id
Expand Down Expand Up @@ -549,6 +550,10 @@ mod tests {
.field_portable(|f| f.name("vec_of_u32".into()).ty(1)),
);
assert_eq!(registry.resolve(2).unwrap(), &expected_ty);

for (idx, ty) in registry.types.iter().enumerate() {
assert_eq!(idx, ty.id as usize);
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion test_suite/tests/ui/fail_missing_derive.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `PawType<u16>: TypeInfo` is not satisfied
--> tests/ui/fail_missing_derive.rs:19:24
|
19 | assert_type_info::<Cat<bool, u8, u16>>();
| ^^^^^^^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `PawType<u16>`
| ^^^^^^^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `PawType<u16>`, which is required by `Cat<bool, u8, u16>: TypeInfo`
|
= help: the following other types implement trait `TypeInfo`:
bool
Expand Down

0 comments on commit 938790b

Please sign in to comment.