Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Mismatched function return type shows error diagnostic in the whole function #301

Closed
joaomoreno opened this issue Apr 25, 2018 · 4 comments

Comments

@joaomoreno
Copy link

The following function fails to return its described return type:

fn foo() -> u32 {
	println!("ok");
}

Ideally, there should be an error decoration under the function's name, or possibly its return type. Currently the decoration spans the entire function implementation, which makes it very hard to notice other error decorations:

image

@nrc
Copy link
Member

nrc commented Apr 30, 2018

We are just using the span from the compiler, so we don't get to choose where we put the squiggle. I agree this seems not great though (and I think it would be not great in the compiler without an IDE too).

cc @estebank

I'm closing this issue since it is a compiler issue, but we might look at opening a compiler issue to fix this.

@nrc nrc closed this as completed Apr 30, 2018
@estebank
Copy link

I believe this would be covered by rust-lang/rust#50009.

Out of curiosity (as I don't use VSCode at the moment), are you displaying secondary spans at all? I intend to change the diagnostic to point at the last line of the scope (in this case println!("ok")), but for real code where the scope would be large, maybe even longer than the screen can show, the function signature might be too far away from the primary span, making it harder to see what the problem is.

@nrc
Copy link
Member

nrc commented Apr 30, 2018

I believe this would be covered by rust-lang/rust#50009.

Awesome!

are you displaying secondary spans at all?

Currently, no, but @Xanewok has been working on adding that now that there is support in VSCode.

@estebank
Copy link

That sounds great. I'll have to sit down and think about some better wording for this diagnostic, maybe even adding a new error code (or extend E0069) with text along the lines of "function body does not return a value of type RETURN_TYPE". That way it wouldn't break expectations when pointing at the function signature when complaining about the body as much as if we were to use the same type mismatch error code.

Xanewok pushed a commit to Xanewok/rls-vscode that referenced this issue Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants