Quick fixes on type mismatch
See original GitHub issueA very basic type checking just merged #1727
Now it’s possible to attach quick fixes to a type mismatch
annotations (on this line). I can imagine the following quick fixes (we assume that A
is actual type, B
is expected type and so a
is a var of type A
. e.g. let a: A = ...; let _: B = a;
):
Coercions:
- If both types are numerics, we can suggest to add a cast
a as B
. - We can have a set of special cases like
str.to_string()
/String.as_str()
- We can try to find
impl From<A> for B
, and if it is exists, suggestB::from(a)
-
From
is not the one type conversion trait. We can also deal withToOwned
/AsRef
/AsMut
/Borrow
/BorrowMut
or evenTryFrom
/FromStr
- We can try to deref
*a
to match required type - We can also get more references
&a
/&mut a
- And any combinations of these, like
&*a
- Or even
&S::from(*a)
Refactorings:
- Suggest to change type of local variable/function/struct field etc. https://github.com/intellij-rust/intellij-rust/pull/5647
- Suggest to change (or add) return type in current function signature #1772
You can find examples of quick fixes in the org.rust.ide.annotator.fixes
package.
You can find more info about how to start contributing to Intellij-Rust in CONTRIBUTING.md, and some info about our architecure in ARCHITECTURE.md. If you have any questions about this issue, you can ask them right here or in our gitter. If you decided to grab this issue, please leave a comment here and put yourself in the worklist.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Type mismatch error, how to quick fix it? - Mr. Excel
arraydic(1,2) is variant/double and arraychess(1,2) is null but type variant/variant(0 to 1) is that the root cause and how do I solve it?...
Read more >VBA Type Mismatch Error - The Ultimate Guide
A VBA Type Mismatch Error occurs when you try to assign a value between two different variable types. The error appears as “run-time...
Read more >how to fix type mismatch error in this specific function?
When I put a toggle point there, the code cannot pass "Duration = Duration + drtn" and "Type MisMatch" error shows up.
Read more >Fix Return Type Mismatch | JustCode Documentation - Telerik
Position the caret over the underlined return expression. · Press Alt+Enter. From the pop-up menu, select Change Type of 'AMethod' to 'int'. Change...
Read more >Add extra quick fix for Type Mismatch error changing type for ...
Add quickfix (one or two separate quicfixes) Cast expression 'findViewById(R.id.textView)' to TextView? and change 'textView' type to TextView?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @vlad20012, no prob, hope you feel better now. Cool, I’ll add the simple cases first.
@vlad20012 here is: