Skip to content

Commit fb2b7e8

Browse files
committed
Rust: Add type inference tests for type aliases
1 parent 1a75c05 commit fb2b7e8

2 files changed

Lines changed: 454 additions & 405 deletions

File tree

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ mod type_aliases {
514514
PairBoth(Fst, Snd),
515515
}
516516

517+
impl<Fst, Snd> PairOption<Fst, Snd> {
518+
fn unwrapSnd(self) -> Snd {
519+
match self {
520+
PairOption::PairNone() => panic!("PairNone has no second element"),
521+
PairOption::PairFst(_) => panic!("PairFst has no second element"),
522+
PairOption::PairSnd(snd) => snd,
523+
PairOption::PairBoth(_, snd) => snd,
524+
}
525+
}
526+
}
527+
517528
#[derive(Debug)]
518529
struct S1;
519530

@@ -527,7 +538,17 @@ mod type_aliases {
527538
type MyPair = PairOption<S1, S2>;
528539

529540
// Generic type alias that partially applies the generic type
530-
type AnotherPair<Thr> = PairOption<S2, Thr>;
541+
type AnotherPair<A3> = PairOption<S2, A3>;
542+
543+
// Alias to another alias
544+
type AliasToAlias<A4> = AnotherPair<A4>;
545+
546+
// Alias that appears nested withing another alias
547+
type NestedAlias<A5> = AnotherPair<AliasToAlias<A5>>;
548+
549+
fn g(t: NestedAlias<S3>) {
550+
println!("{:?}", t.unwrapSnd().unwrapSnd()); // missing
551+
}
531552

532553
pub fn f() {
533554
// Type can be inferred from the constructor
@@ -545,6 +566,8 @@ mod type_aliases {
545566
// First type from alias definition, second from argument to alias
546567
let p3: AnotherPair<S3> = PairOption::PairNone(); // type for `Snd` missing, spurious `S3` for `Fst`
547568
println!("{:?}", p3);
569+
570+
g(PairOption::PairSnd(PairOption::PairSnd(S3))); // missing
548571
}
549572
}
550573

0 commit comments

Comments
 (0)