diff --git a/crates/uitest/fixtures/ty_check/functor.fe b/crates/hir-analysis/test_files/ty_check/refinement.fe similarity index 75% rename from crates/uitest/fixtures/ty_check/functor.fe rename to crates/hir-analysis/test_files/ty_check/refinement.fe index 51e06ef36..0d90299d3 100644 --- a/crates/uitest/fixtures/ty_check/functor.fe +++ b/crates/hir-analysis/test_files/ty_check/refinement.fe @@ -24,7 +24,7 @@ impl Fn for MyFn { } } -impl Functor for Result<()> { +impl Functor for Result { fn map>(self: Self, _ f: F) -> Self { match self { Result::Ok(t) => Result::Ok(f.call(t)) @@ -35,5 +35,20 @@ impl Functor for Result<()> { fn f() { let r1 = Result<(), i32>::Ok(10) - let r2 = r1.map(MyFn{}) // TODO: type of r2 should be inferred + let r2 = r1.map(MyFn{}) +} + + +trait MyTrait {} +impl MyTrait for i32 {} + +fn g() -> T + where T: MyTrait +{ + todo() + +} + +fn h() { + let _ = g() } diff --git a/crates/hir-analysis/test_files/ty_check/refinement.snap b/crates/hir-analysis/test_files/ty_check/refinement.snap new file mode 100644 index 000000000..f0b09b8f3 --- /dev/null +++ b/crates/hir-analysis/test_files/ty_check/refinement.snap @@ -0,0 +1,224 @@ +--- +source: crates/hir-analysis/tests/ty_check.rs +expression: res +input_file: crates/hir-analysis/test_files/ty_check/refinement.fe +--- +note: + ┌─ refinement.fe:22:37 + │ +22 │ fn call(self, _ t: i32) -> bool { + │ ╭─────────────────────────────────────^ +23 │ │ return true +24 │ │ } + │ ╰─────^ bool + +note: + ┌─ refinement.fe:23:16 + │ +23 │ return true + │ ^^^^ bool + +note: + ┌─ refinement.fe:28:65 + │ +28 │ fn map>(self: Self, _ f: F) -> Self { + │ ╭─────────────────────────────────────────────────────────────────^ +29 │ │ match self { +30 │ │ Result::Ok(t) => Result::Ok(f.call(t)) +31 │ │ Result::Err(e) => Result::Err(e) +32 │ │ } +33 │ │ } + │ ╰─────^ Result + +note: + ┌─ refinement.fe:29:9 + │ +29 │ ╭ match self { +30 │ │ Result::Ok(t) => Result::Ok(f.call(t)) +31 │ │ Result::Err(e) => Result::Err(e) +32 │ │ } + │ ╰─────────^ Result + +note: + ┌─ refinement.fe:29:15 + │ +29 │ match self { + │ ^^^^ Result + +note: + ┌─ refinement.fe:30:13 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^^^^^^^^^^^^^ Result + +note: + ┌─ refinement.fe:30:24 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^ T + +note: + ┌─ refinement.fe:30:30 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^^^^^^^^^^ fn Ok + +note: + ┌─ refinement.fe:30:30 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^^^^^^^^^^^^^^^^^^^^^ Result + +note: + ┌─ refinement.fe:30:41 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^ F + +note: + ┌─ refinement.fe:30:41 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^^^^^^^^^ U + +note: + ┌─ refinement.fe:30:48 + │ +30 │ Result::Ok(t) => Result::Ok(f.call(t)) + │ ^ T + +note: + ┌─ refinement.fe:31:13 + │ +31 │ Result::Err(e) => Result::Err(e) + │ ^^^^^^^^^^^^^^ Result + +note: + ┌─ refinement.fe:31:25 + │ +31 │ Result::Err(e) => Result::Err(e) + │ ^ E + +note: + ┌─ refinement.fe:31:31 + │ +31 │ Result::Err(e) => Result::Err(e) + │ ^^^^^^^^^^^ fn Err + +note: + ┌─ refinement.fe:31:31 + │ +31 │ Result::Err(e) => Result::Err(e) + │ ^^^^^^^^^^^^^^ Result + +note: + ┌─ refinement.fe:31:43 + │ +31 │ Result::Err(e) => Result::Err(e) + │ ^ E + +note: + ┌─ refinement.fe:36:8 + │ +36 │ fn f() { + │ ╭────────^ +37 │ │ let r1 = Result<(), i32>::Ok(10) +38 │ │ let r2 = r1.map(MyFn{}) +39 │ │ } + │ ╰─^ () + +note: + ┌─ refinement.fe:37:9 + │ +37 │ let r1 = Result<(), i32>::Ok(10) + │ ^^ Result<(), i32> + +note: + ┌─ refinement.fe:37:14 + │ +37 │ let r1 = Result<(), i32>::Ok(10) + │ ^^^^^^^^^^^^^^^^^^^ fn Ok<(), i32> + +note: + ┌─ refinement.fe:37:14 + │ +37 │ let r1 = Result<(), i32>::Ok(10) + │ ^^^^^^^^^^^^^^^^^^^^^^^ Result<(), i32> + +note: + ┌─ refinement.fe:37:34 + │ +37 │ let r1 = Result<(), i32>::Ok(10) + │ ^^ i32 + +note: + ┌─ refinement.fe:38:9 + │ +38 │ let r2 = r1.map(MyFn{}) + │ ^^ Result<(), bool> + +note: + ┌─ refinement.fe:38:14 + │ +38 │ let r2 = r1.map(MyFn{}) + │ ^^ Result<(), i32> + +note: + ┌─ refinement.fe:38:14 + │ +38 │ let r2 = r1.map(MyFn{}) + │ ^^^^^^^^^^^^^^ Result<(), bool> + +note: + ┌─ refinement.fe:38:21 + │ +38 │ let r2 = r1.map(MyFn{}) + │ ^^^^^^ MyFn + +note: + ┌─ refinement.fe:47:1 + │ +47 │ ╭ { +48 │ │ todo() +49 │ │ +50 │ │ } + │ ╰─^ T + +note: + ┌─ refinement.fe:48:5 + │ +48 │ todo() + │ ^^^^ fn todo + +note: + ┌─ refinement.fe:48:5 + │ +48 │ todo() + │ ^^^^^^ T + +note: + ┌─ refinement.fe:52:8 + │ +52 │ fn h() { + │ ╭────────^ +53 │ │ let _ = g() +54 │ │ } + │ ╰─^ () + +note: + ┌─ refinement.fe:53:9 + │ +53 │ let _ = g() + │ ^ i32 + +note: + ┌─ refinement.fe:53:13 + │ +53 │ let _ = g() + │ ^ fn g + +note: + ┌─ refinement.fe:53:13 + │ +53 │ let _ = g() + │ ^^^ i32 diff --git a/crates/uitest/fixtures/ty_check/functor.snap b/crates/uitest/fixtures/ty_check/functor.snap deleted file mode 100644 index 24a4dad69..000000000 --- a/crates/uitest/fixtures/ty_check/functor.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: crates/uitest/tests/ty_check.rs -expression: diags -input_file: crates/uitest/fixtures/ty_check/functor.fe ---- -error[8-0031]: type annotation is needed - ┌─ functor.fe:38:9 - │ -38 │ let r2 = r1.map(MyFn{}) // TODO: type of r2 should be inferred - │ ^^ - │ │ - │ type annotation is needed - │ consider giving `: Result<(), _>` here diff --git a/crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe b/crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe index ecf95b500..a40c4d7dc 100644 --- a/crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe +++ b/crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe @@ -51,10 +51,16 @@ impl Clone for bool { } } +impl Clone for i32 { + fn clone(self) -> i32 { + self + } +} + fn foo() -> i32 { let s = S::new(false) extract(s) let opt = Some(1) extract(opt) -} \ No newline at end of file +} diff --git a/crates/uitest/fixtures/ty_check/method_bound/arg_bound.snap b/crates/uitest/fixtures/ty_check/method_bound/arg_bound.snap index 078e44557..421957c32 100644 --- a/crates/uitest/fixtures/ty_check/method_bound/arg_bound.snap +++ b/crates/uitest/fixtures/ty_check/method_bound/arg_bound.snap @@ -4,15 +4,7 @@ expression: diags input_file: crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe --- error[6-0003]: trait bound is not satisfied - ┌─ arg_bound.fe:56:5 + ┌─ arg_bound.fe:62:5 │ -56 │ extract(s) +62 │ extract(s) │ ^^^^^^^ `S` doesn't implement `Extract` - -error[6-0003]: trait bound is not satisfied - ┌─ arg_bound.fe:59:5 - │ -59 │ extract(opt) - │ ^^^^^^^ `i32` doesn't implement `Clone` - -