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.

Infer the type of `x` in `val f: (Int => Int) | Unit = x => x + 1`

See original GitHub issue

Or more generally, try harder to infer function literal parameter types from expected type which are unions. The | Unit usecases matters particularly for scala.js where it’s not uncommon for a parameter type to be written that way (because Unit corresponds to undefined in scala.js) but I assume that the explicit nulls language feature could run into the same sort of issues.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
noti0na1commented, Mar 10, 2021

@smarter I can work on this. I think finding the leftmost function type/SAM in the union type would be enough.

0reactions
sjrdcommented, Mar 11, 2021

I agree with @LPTK. Anything that is not symmetrical will be very volatile.

To avoid backtracking, consider going through the list of elements of the union and throw away the ones that are not SAM types. If you’re left with 1, all good, otherwise abandon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

9.6. Type Inference — OCaml Programming - GitHub Pages
Type Inference #. OCaml and Java are statically typed languages, meaning every binding has a type that is determined at compile time—that is,...
Read more >
Type Checking and Type Inference
Type Checking and Type Inference. Type Inference. 1 ... fun f x = (* infer val f : int -> int *) if...
Read more >
Inferred type in for comprehension - scala - Stack Overflow
The problem is that the type of the if expression if (bar.cond) `foo.map` += 1 -> "a" else `foo.set` += 2. is State[Foo,...
Read more >
Types, Type Inference and Unification
Even integers. {f:int → int | x>3 => f(x) > x *(x+1)}. Distinction between sets of values that are types and sets that...
Read more >
Common Error Messages · OCaml Tutorials
"This expression has type X but is here used with type Y" means that if the contents of the expression is isolated (2.5),...
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