question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quick fixes on type mismatch

See original GitHub issue

A 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, suggest B::from(a)
  • From is not the one type conversion trait. We can also deal with ToOwned/AsRef/AsMut/Borrow/BorrowMut or even TryFrom/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:

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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
oleg-semenovcommented, Dec 16, 2017

Thanks @vlad20012, no prob, hope you feel better now. Cool, I’ll add the simple cases first.

0reactions
oleg-semenovcommented, May 12, 2018

@vlad20012 here is:

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found