From d86f6bd47091b8fea19dcec021a370372885839a Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sat, 20 Apr 2024 22:12:39 +0200 Subject: [PATCH] [WIP] Add more tests --- .../ty_check/method/infer_by_method.fe | 13 ++++++ .../ty_check/method/infer_by_method.snap | 46 +++++++++++++++++++ .../ty_check/method_selection/ambiguous.fe | 36 +++++++++++++++ .../ty_check/method_selection/ambiguous.snap | 27 +++++++++++ 4 files changed, 122 insertions(+) create mode 100644 crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe create mode 100644 crates/hir-analysis/test_files/ty_check/method/infer_by_method.snap create mode 100644 crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe create mode 100644 crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap diff --git a/crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe b/crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe new file mode 100644 index 000000000..773f36214 --- /dev/null +++ b/crates/hir-analysis/test_files/ty_check/method/infer_by_method.fe @@ -0,0 +1,13 @@ +enum Option { + Some(T), + None +} + +impl Option { + fn foo(self) {} +} + +fn foo() { + let x = Option::None + x.foo() +} \ No newline at end of file diff --git a/crates/hir-analysis/test_files/ty_check/method/infer_by_method.snap b/crates/hir-analysis/test_files/ty_check/method/infer_by_method.snap new file mode 100644 index 000000000..ee61a023b --- /dev/null +++ b/crates/hir-analysis/test_files/ty_check/method/infer_by_method.snap @@ -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 + +note: + ┌─ test_file.fe:11:13 + │ +11 │ let x = Option::None + │ ^^^^^^^^^^^^ Option + +note: + ┌─ test_file.fe:12:5 + │ +12 │ x.foo() + │ ^ Option + +note: + ┌─ test_file.fe:12:5 + │ +12 │ x.foo() + │ ^^^^^^^ () + + diff --git a/crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe b/crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe new file mode 100644 index 000000000..de0a5e8c5 --- /dev/null +++ b/crates/uitest/fixtures/ty_check/method_selection/ambiguous.fe @@ -0,0 +1,36 @@ +struct Foo { + x: i32, + y: T, +} + +trait Default { + fn default() -> Self +} + +impl Default for Foo +where T: Default +{ + fn default() -> Self { + Self { + x: 0, + y: T::default() + } + } +} + +impl Foo { + fn foo(self) -> i32 { + self.x + } +} + +impl Foo { + fn foo(self) -> u32 { + self.y + } +} + +fn bar() { + let f = Foo::default() + f.foo() +} \ No newline at end of file diff --git a/crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap b/crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap new file mode 100644 index 000000000..30471809a --- /dev/null +++ b/crates/uitest/fixtures/ty_check/method_selection/ambiguous.snap @@ -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 + +