Skip to content

Commit 6f21df8

Browse files
committed
Rust: Add type inference tests for type aliases
1 parent f4105ee commit 6f21df8

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
@@ -530,6 +530,17 @@ mod type_aliases {
530530
PairBoth(Fst, Snd),
531531
}
532532

533+
impl<Fst, Snd> PairOption<Fst, Snd> {
534+
fn unwrapSnd(self) -> Snd {
535+
match self {
536+
PairOption::PairNone() => panic!("PairNone has no second element"),
537+
PairOption::PairFst(_) => panic!("PairFst has no second element"),
538+
PairOption::PairSnd(snd) => snd,
539+
PairOption::PairBoth(_, snd) => snd,
540+
}
541+
}
542+
}
543+
533544
#[derive(Debug)]
534545
struct S1;
535546

@@ -543,7 +554,17 @@ mod type_aliases {
543554
type MyPair = PairOption<S1, S2>;
544555

545556
// Generic type alias that partially applies the generic type
546-
type AnotherPair<Thr> = PairOption<S2, Thr>;
557+
type AnotherPair<A3> = PairOption<S2, A3>;
558+
559+
// Alias to another alias
560+
type AliasToAlias<A4> = AnotherPair<A4>;
561+
562+
// Alias that appears nested withing another alias
563+
type NestedAlias<A5> = AnotherPair<AliasToAlias<A5>>;
564+
565+
fn g(t: NestedAlias<S3>) {
566+
println!("{:?}", t.unwrapSnd().unwrapSnd()); // missing
567+
}
547568

548569
pub fn f() {
549570
// Type can be inferred from the constructor
@@ -561,6 +582,8 @@ mod type_aliases {
561582
// First type from alias definition, second from argument to alias
562583
let p3: AnotherPair<S3> = PairOption::PairNone(); // type for `Snd` missing, spurious `S3` for `Fst`
563584
println!("{:?}", p3);
585+
586+
g(PairOption::PairSnd(PairOption::PairSnd(S3))); // missing
564587
}
565588
}
566589

0 commit comments

Comments
 (0)