Skip to content

Commit

Permalink
Merge #7007
Browse files Browse the repository at this point in the history
7007: TY: fix unification with `!` in match arms r=ortem a=vlad20012

Fixes #6749


Co-authored-by: vlad20012 <beskvlad@gmail.com>
  • Loading branch information
bors[bot] and vlad20012 committed Mar 23, 2021
2 parents 6ebc960 + 0a3f5d3 commit 21ff1b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1340,12 +1340,15 @@ class RsTypeInferenceWalker(
}

// TODO should be replaced with coerceMany
private fun getMoreCompleteType(ty1: Ty, ty2: Ty): Ty = when (ty1) {
is TyNever -> ty2
is TyUnknown -> if (ty2 !is TyNever) ty2 else TyUnknown
else -> {
ctx.combineTypes(ty1, ty2)
ty1
private fun getMoreCompleteType(ty1: Ty, ty2: Ty): Ty {
return when {
ty1 is TyNever -> ty2
ty2 is TyNever -> ty1
ty1 is TyUnknown -> if (ty2 !is TyNever) ty2 else TyUnknown
else -> {
ctx.combineTypes(ty1, ty2)
ty1
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,19 @@ class RsStdlibExpressionTypeInferenceTest : RsTypificationTestBase() {
b;
} //^ S
""")

// Issue https://github.com/intellij-rust/intellij-rust/issues/6749
fun `test diverging and non-diverging match arm`() = stubOnlyTypeInfer("""
//- main.rs
fn foo(x: i32) {}
fn main() {
let num2 = match "42".parse() {
Ok(v) => v,
Err(e) => panic!(),
}; // type of `num2` should be `i32`, not `!`
foo(num2);
num2;
} //^ i32
""")
}

0 comments on commit 21ff1b0

Please sign in to comment.