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.

Type check mismatch

See original GitHub issue

Compiler version

3.0.0

Minimized code

case class G[A, X[_]](x: X[A])

enum Boxes[A]:
  case IntBox(a: Int)
  case StringBox(a: String)
import Boxes._

def f(i: Int): G[Int, Boxes] =
  val box = IntBox(i)
  return G(box)

Output

Found:    (box : Boxes[Nothing])
Required: Boxes[Int]
  return G(box)

Expectation

Behave the same as the in-line version (which does work)

...
def g(i: Int): G[Int, Boxes] =
  return G(IntBox(i))

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dwijnandcommented, Jul 27, 2021

This is, as I understand it, fundamentally down to the fact that the type system has subtyping.

0reactions
Adam-Vandervorstcommented, Jul 27, 2021

The typer is working with information it has during type inference. It is not taking into account potential future uses of the value.

Maybe taking into account future uses is something useful to do, especially in trivial cases like this. Going along that, the error messaging could be improved here: Found: (box : Boxes[Nothing]) implies this type was given by the user. In more difficult cases where the “taking into account future uses” fails, a clearer error message could read:

Could not find a type for
  val box = IntBox(i)
that satisfies required type(s): 
Boxes[Int]
  return G(box)

This may significantly improve the comfort, while avoiding breaking the equivalence stated above as much as possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
I get a message about data type mismatch
I get a message about data type mismatch ... This error indicates that Access cannot match an input value to the data type...
Read more >
Type checking errors
This section lists all errors that can occur when type checking is performed. Error: Type mismatch: This can happen in many cases: The...
Read more >
Type mismatch error when types are verified
I get a type mismatch error when calling OutputEntry with the first ... fine and does get called inside of that type checking...
Read more >
Understanding Elm's Type Mismatch Error
If you see a function in a Type Mismatch error, you'll want to check that the function has been passed all its arguments...
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