From 4fc233a02e8dc07619a969400c445ec47c2b1a9d Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Sat, 5 Jan 2019 21:28:30 +0100 Subject: Implement type inference for boolean operators --- crates/ra_hir/src/ty/tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index fb53fcf0b..97c466890 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -153,6 +153,23 @@ impl S { ); } +#[test] +fn infer_boolean_op() { + check_inference( + r#" +fn test() { + let x = a && b; + let y = true || false; + let z = x == y; + let h = CONST_1 <= CONST_2; + + 10 < 3 +} +"#, + "0008_boolean_op.txt", + ); +} + fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); let source_file = db.source_file(file_id); -- cgit v1.2.3 From 82d9a77dade454ee8d09f198fa839e7755ff7bfb Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Sun, 6 Jan 2019 21:39:36 +0100 Subject: Touch up type inference for boolean operators Also try to infer its subexpressions and set type expectations whenever possible. --- crates/ra_hir/src/ty/tests.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 97c466890..1650606b7 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -157,11 +157,18 @@ impl S { fn infer_boolean_op() { check_inference( r#" +fn f(x: bool) -> i32 { + 0i32 +} + fn test() { let x = a && b; let y = true || false; let z = x == y; let h = CONST_1 <= CONST_2; + let c = f(z || y) + 5; + let d = b; + let e = 3i32 && "hello world"; 10 < 3 } -- cgit v1.2.3