Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/diagnostics.rs')
| -rw-r--r-- | crates/hir-ty/src/tests/diagnostics.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/crates/hir-ty/src/tests/diagnostics.rs b/crates/hir-ty/src/tests/diagnostics.rs index d0d31bf2a5..855034117c 100644 --- a/crates/hir-ty/src/tests/diagnostics.rs +++ b/crates/hir-ty/src/tests/diagnostics.rs @@ -159,18 +159,18 @@ fn method_call_on_field() { check( r#" struct S { - field: fn() -> u32, + field: fn(f32) -> u32, field2: u32 } fn main() { - let s = S { field: || 0, field2: 0 }; + let s = S { field: |_| 0, field2: 0 }; s.field(0); - // ^ type: i32 + // ^ expected f32, got i32 // ^^^^^^^^^^ type: u32 s.field2(0); // ^ type: i32 - // ^^^^^^^^^^^ type: u32 + // ^^^^^^^^^^^ type: {unknown} s.not_a_field(0); // ^ type: i32 // ^^^^^^^^^^^^^^^^ type: {unknown} @@ -178,3 +178,28 @@ fn main() { "#, ); } + +#[test] +fn method_call_on_assoc() { + check( + r#" +struct S; + +impl S { + fn not_a_method() -> f32 { 0.0 } + fn not_a_method2(this: Self, param: f32) -> Self { this } + fn not_a_method3(param: f32) -> Self { S } +} + +fn main() { + S.not_a_method(0); + // ^^^^^^^^^^^^^^^^^ type: f32 + S.not_a_method2(0); + // ^ expected f32, got i32 + // ^^^^^^^^^^^^^^^^^^ type: S + S.not_a_method3(0); + // ^^^^^^^^^^^^^^^^^^ type: S +} +"#, + ); +} |