-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
46 changes: 46 additions & 0 deletions
46
crates/hir-analysis/test_files/ty_check/method/infer_by_method.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
│ | ||
7 │ fn foo(self) {} | ||
│ ^^ () | ||
|
||
note: | ||
┌─ test_file.fe:10:10 | ||
│ | ||
10 │ fn foo() { | ||
│ ╭──────────^ | ||
11 │ │ let x = Option::None | ||
12 │ │ x.foo() | ||
13 │ │ } | ||
│ ╰─^ () | ||
|
||
note: | ||
┌─ test_file.fe:11:9 | ||
│ | ||
11 │ let 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
36
crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
│ | ||
22 │ fn foo(self) -> i32 { | ||
│ --- foo is defined here | ||
· | ||
28 │ fn foo(self) -> u32 { | ||
│ --- foo is defined here | ||
· | ||
35 │ f.foo() | ||
│ ^^^ `foo` is ambiguous | ||
|
||
error[8-0030]: type annotation is needed | ||
┌─ ambiguous.fe:34:9 | ||
│ | ||
34 │ let f = Foo::default() | ||
│ ^ | ||
│ │ | ||
│ type annotation is needed | ||
│ consider giving `: Foo<_>` here | ||
|
||
|