Skip to content

Commit ae6eb67

Browse files
dzfranklindwrensha
authored andcommitted
bugfix: make subset use correct index when constructing Type
1 parent 39a5248 commit ae6eb67

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

capnp/src/schema.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ impl FieldSubset {
204204
}
205205

206206
pub fn get(self, index: u16) -> Field {
207+
let index = self.indices[index as usize];
207208
Field {
208-
proto: self.fields.get(self.indices[index as usize] as u32),
209+
proto: self.fields.get(index as u32),
209210
index,
210211
parent: self.parent,
211212
}

capnpc/test/test.capnp

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424

2525
using Rust = import "rust.capnp";
2626

27+
struct FieldSubsetIndexesCorrectly {
28+
common @2 :Text;
29+
30+
union {
31+
unset @0 :Void;
32+
variant @1 :UInt8;
33+
}
34+
}
35+
2736
struct TestPrimList {
2837
uint8List @0 : List(UInt8);
2938
int8List @1 : List(Int8);

capnpc/test/test.rs

+16
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ mod tests {
106106
};
107107
}
108108

109+
#[test]
110+
fn field_subset_indexes_corrently() {
111+
use crate::test_capnp::field_subset_indexes_correctly;
112+
use capnp::{
113+
introspect::{Introspect, TypeVariant},
114+
schema::StructSchema,
115+
};
116+
117+
let TypeVariant::Struct(schema) = field_subset_indexes_correctly::Owned::introspect().which() else { unreachable!() };
118+
let schema = StructSchema::new(schema);
119+
120+
let subset = schema.get_non_union_fields().unwrap();
121+
let field = subset.get(0);
122+
assert_matches!(field.get_type().which(), TypeVariant::Text);
123+
}
124+
109125
#[test]
110126
fn test_prim_list() {
111127
use crate::test_capnp::test_prim_list;

0 commit comments

Comments
 (0)