Skip to content

Commit aa45448

Browse files
authored
fix: Use List instead of Tuple in conversions for TypeArg/TypeRow (#2378)
Conversions introduced in #2366 were expecting `Term::Tuples` instead of `Term::List`. This fixes this.
1 parent 3f7d5cb commit aa45448

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

hugr-core/src/types/type_row.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub struct TypeRowBase<ROWVARS: MaybeRV> {
2828
/// Row of single types i.e. of known length, for node inputs/outputs
2929
pub type TypeRow = TypeRowBase<NoRV>;
3030

31-
/// Row of types and/or row variables, the number of actual types is thus unknown
31+
/// Row of types and/or row variables, the number of actual types is thus
32+
/// unknown
3233
pub type TypeRowRV = TypeRowBase<RowVariable>;
3334

3435
impl<RV1: MaybeRV, RV2: MaybeRV> PartialEq<TypeRowBase<RV1>> for TypeRowBase<RV2> {
@@ -223,7 +224,7 @@ impl TryFrom<Term> for TypeRow {
223224

224225
fn try_from(value: TypeArg) -> Result<Self, Self::Error> {
225226
match value {
226-
TypeArg::Tuple(elems) => elems
227+
TypeArg::List(elems) => elems
227228
.into_iter()
228229
.map(|ta| ta.as_runtime())
229230
.collect::<Option<Vec<_>>>()
@@ -242,7 +243,7 @@ impl TryFrom<Term> for TypeRowRV {
242243

243244
fn try_from(value: Term) -> Result<Self, Self::Error> {
244245
match value {
245-
TypeArg::Tuple(elems) => elems
246+
TypeArg::List(elems) => elems
246247
.into_iter()
247248
.map(TypeRV::try_from)
248249
.collect::<Result<Vec<_>, _>>()
@@ -260,13 +261,13 @@ impl TryFrom<Term> for TypeRowRV {
260261

261262
impl From<TypeRow> for Term {
262263
fn from(value: TypeRow) -> Self {
263-
Term::Tuple(value.into_owned().into_iter().map_into().collect())
264+
Term::List(value.into_owned().into_iter().map_into().collect())
264265
}
265266
}
266267

267268
impl From<TypeRowRV> for Term {
268269
fn from(value: TypeRowRV) -> Self {
269-
Term::Tuple(value.into_owned().into_iter().map_into().collect())
270+
Term::List(value.into_owned().into_iter().map_into().collect())
270271
}
271272
}
272273

@@ -330,26 +331,26 @@ mod test {
330331

331332
#[test]
332333
fn test_try_from_term_to_typerow() {
333-
// Test successful conversion with Tuple
334+
// Test successful conversion with List
334335
let types = vec![Type::new_unit_sum(1), bool_t()];
335336
let type_args = types.iter().map(|t| TypeArg::Runtime(t.clone())).collect();
336-
let term = TypeArg::Tuple(type_args);
337+
let term = TypeArg::List(type_args);
337338
let result = TypeRow::try_from(term);
338339
assert!(result.is_ok());
339340
assert_eq!(result.unwrap(), TypeRow::from(types));
340341

341-
// Test failure with non-tuple
342+
// Test failure with non-list
342343
let term = TypeArg::Runtime(Type::UNIT);
343344
let result = TypeRow::try_from(term);
344345
assert!(result.is_err());
345346
}
346347

347348
#[test]
348349
fn test_try_from_term_to_typerowrv() {
349-
// Test successful conversion with Tuple
350+
// Test successful conversion with List
350351
let types = [TypeRV::from(Type::UNIT), TypeRV::from(bool_t())];
351352
let type_args = types.iter().map(|t| t.clone().into()).collect();
352-
let term = TypeArg::Tuple(type_args);
353+
let term = TypeArg::List(type_args);
353354
let result = TypeRowRV::try_from(term);
354355
assert!(result.is_ok());
355356

@@ -366,10 +367,10 @@ mod test {
366367
let term = Term::from(type_row);
367368

368369
match term {
369-
Term::Tuple(elems) => {
370+
Term::List(elems) => {
370371
assert_eq!(elems.len(), 2);
371372
}
372-
_ => panic!("Expected Term::Tuple"),
373+
_ => panic!("Expected Term::List"),
373374
}
374375
}
375376

@@ -380,10 +381,10 @@ mod test {
380381
let term = Term::from(type_row_rv);
381382

382383
match term {
383-
TypeArg::Tuple(elems) => {
384+
TypeArg::List(elems) => {
384385
assert_eq!(elems.len(), 2);
385386
}
386-
_ => panic!("Expected Term::Tuple"),
387+
_ => panic!("Expected Term::List"),
387388
}
388389
}
389390
}

0 commit comments

Comments
 (0)