Skip to content

Commit

Permalink
[WIP] Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Apr 20, 2024
1 parent fe3a8a5 commit d86f6bd
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum Option<T> {
Some(T),
None
}

impl Option<i32> {
fn foo(self) {}
}

fn foo() {
let x = Option::None
x.foo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
source: crates/hir-analysis/tests/ty_check.rs
expression: res
input_file: crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe
---
note:
┌─ test_file.fe:7:18
7fn foo(self) {}
^^ ()

note:
┌─ test_file.fe:10:10
10fn foo() {
│ ╭──────────^
11 │ │ let x = Option::None
12 │ │ x.foo()
13 │ │ }
│ ╰─^ ()

note:
┌─ test_file.fe:11:9
11let x = Option::None
^ Option<i32>

note:
┌─ test_file.fe:11:13
11 │ let x = Option::None
│ ^^^^^^^^^^^^ Option<i32>

note:
┌─ test_file.fe:12:5
12 │ x.foo()
│ ^ Option<i32>

note:
┌─ test_file.fe:12:5
12 │ x.foo()
│ ^^^^^^^ ()


36 changes: 36 additions & 0 deletions crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
struct Foo<T> {
x: i32,
y: T,
}

trait Default {
fn default() -> Self
}

impl<T> Default for Foo<T>
where T: Default
{
fn default() -> Self {
Self {
x: 0,
y: T::default()
}
}
}

impl Foo<i32> {
fn foo(self) -> i32 {
self.x
}
}

impl Foo<u32> {
fn foo(self) -> u32 {
self.y
}
}

fn bar() {
let f = Foo::default()
f.foo()
}
27 changes: 27 additions & 0 deletions crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: crates/uitest/tests/ty_check.rs
expression: diags
input_file: crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe
---
error[8-0025]: ambiguous method call
┌─ ambiguous.fe:35:7
22fn foo(self) -> i32 {
--- foo is defined here
·
28fn foo(self) -> u32 {
--- foo is defined here
·
35f.foo()
^^^ `foo` is ambiguous

error[8-0030]: type annotation is needed
┌─ ambiguous.fe:34:9
34let f = Foo::default()
^
│ │
type annotation is needed
consider giving `: Foo<_>` here


0 comments on commit d86f6bd

Please sign in to comment.