Skip to content

Commit

Permalink
Add refinement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Jan 15, 2025
1 parent 02bbf68 commit b4bb192
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Fn<i32, bool> for MyFn {
}
}

impl Functor for Result<()> {
impl<E> Functor for Result<E> {
fn map<T, U, F: Fn<T, U>>(self: Self<T>, _ f: F) -> Self<U> {
match self {
Result::Ok(t) => Result::Ok(f.call(t))
Expand All @@ -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>() -> T
where T: MyTrait
{
todo()

}

fn h() {
let _ = g()
}
224 changes: 224 additions & 0 deletions crates/hir-analysis/test_files/ty_check/refinement.snap
Original file line number Diff line number Diff line change
@@ -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
22fn call(self, _ t: i32) -> bool {
│ ╭─────────────────────────────────────^
23 │ │ return true
24 │ │ }
│ ╰─────^ bool

note:
┌─ refinement.fe:23:16
23return true
^^^^ bool

note:
┌─ refinement.fe:28:65
28fn map<T, U, F: Fn<T, U>>(self: Self<T>, _ f: F) -> Self<U> {
│ ╭─────────────────────────────────────────────────────────────────^
29 │ │ match self {
30 │ │ Result::Ok(t) => Result::Ok(f.call(t))
31 │ │ Result::Err(e) => Result::Err(e)
32 │ │ }
33 │ │ }
│ ╰─────^ Result<E, U>

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<E, U>

note:
┌─ refinement.fe:29:15
29 │ match self {
^^^^ Result<E, T>

note:
┌─ refinement.fe:30:13
30Result::Ok(t) => Result::Ok(f.call(t))
^^^^^^^^^^^^^ Result<E, T>

note:
┌─ refinement.fe:30:24
30Result::Ok(t) => Result::Ok(f.call(t))
^ T

note:
┌─ refinement.fe:30:30
30Result::Ok(t) => Result::Ok(f.call(t))
^^^^^^^^^^ fn Ok<E, U>

note:
┌─ refinement.fe:30:30
30Result::Ok(t) => Result::Ok(f.call(t))
^^^^^^^^^^^^^^^^^^^^^ Result<E, U>

note:
┌─ refinement.fe:30:41
30Result::Ok(t) => Result::Ok(f.call(t))
^ F

note:
┌─ refinement.fe:30:41
30Result::Ok(t) => Result::Ok(f.call(t))
^^^^^^^^^ U

note:
┌─ refinement.fe:30:48
30Result::Ok(t) => Result::Ok(f.call(t))
^ T

note:
┌─ refinement.fe:31:13
31Result::Err(e) => Result::Err(e)
^^^^^^^^^^^^^^ Result<E, T>

note:
┌─ refinement.fe:31:25
31Result::Err(e) => Result::Err(e)
^ E

note:
┌─ refinement.fe:31:31
31Result::Err(e) => Result::Err(e)
^^^^^^^^^^^ fn Err<E, U>

note:
┌─ refinement.fe:31:31
31Result::Err(e) => Result::Err(e)
^^^^^^^^^^^^^^ Result<E, U>

note:
┌─ refinement.fe:31:43
31Result::Err(e) => Result::Err(e)
^ E

note:
┌─ refinement.fe:36:8
36fn f() {
│ ╭────────^
37 │ │ let r1 = Result<(), i32>::Ok(10)
38 │ │ let r2 = r1.map(MyFn{})
39 │ │ }
│ ╰─^ ()

note:
┌─ refinement.fe:37:9
37let r1 = Result<(), i32>::Ok(10)
^^ Result<(), i32>

note:
┌─ refinement.fe:37:14
37let r1 = Result<(), i32>::Ok(10)
^^^^^^^^^^^^^^^^^^^ fn Ok<(), i32>

note:
┌─ refinement.fe:37:14
37let r1 = Result<(), i32>::Ok(10)
^^^^^^^^^^^^^^^^^^^^^^^ Result<(), i32>

note:
┌─ refinement.fe:37:34
37let r1 = Result<(), i32>::Ok(10)
^^ i32

note:
┌─ refinement.fe:38:9
38let r2 = r1.map(MyFn{})
^^ Result<(), bool>

note:
┌─ refinement.fe:38:14
38let r2 = r1.map(MyFn{})
^^ Result<(), i32>

note:
┌─ refinement.fe:38:14
38let r2 = r1.map(MyFn{})
^^^^^^^^^^^^^^ Result<(), bool>

note:
┌─ refinement.fe:38:21
38let r2 = r1.map(MyFn{})
^^^^^^ MyFn

note:
┌─ refinement.fe:47:1
47 │ ╭ {
48 │ │ todo()
49 │ │
50 │ │ }
│ ╰─^ T

note:
┌─ refinement.fe:48:5
48todo()
^^^^ fn todo

note:
┌─ refinement.fe:48:5
48todo()
^^^^^^ T

note:
┌─ refinement.fe:52:8
52fn h() {
│ ╭────────^
53 │ │ let _ = g()
54 │ │ }
│ ╰─^ ()

note:
┌─ refinement.fe:53:9
53let _ = g()
^ i32

note:
┌─ refinement.fe:53:13
53let _ = g()
^ fn g<i32>

note:
┌─ refinement.fe:53:13
53 │ let _ = g()
│ ^^^ i32
13 changes: 0 additions & 13 deletions crates/uitest/fixtures/ty_check/functor.snap

This file was deleted.

8 changes: 7 additions & 1 deletion crates/uitest/fixtures/ty_check/method_bound/arg_bound.fe
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 2 additions & 10 deletions crates/uitest/fixtures/ty_check/method_bound/arg_bound.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
56extract(s)
62extract(s)
^^^^^^^ `S` doesn't implement `Extract`

error[6-0003]: trait bound is not satisfied
┌─ arg_bound.fe:59:5
59extract(opt)
^^^^^^^ `i32` doesn't implement `Clone`


0 comments on commit b4bb192

Please sign in to comment.