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.

[Regression in 3.1.2-RC1] Inferred union in type argument position gets widened

See original GitHub issue

Compiler version

3.1.2-RC1

First bad commit 3ab18a90ac24dba440c498aab6a8f0c763589605 in https://github.com/lampepfl/dotty/pull/14026

Minimized code

object ImplNotFound:
  def main(args: Array[String]): Unit =
    val res: Seq[String | Int] = (??? : Seq[Int]).collect {
      case 1 => Seq("")
      case 2 => Seq(1)
    }.flatten

Output

[error] -- Error: /.../ImplNotFound.scala:6:13 
[error] 6 |    }.flatten
[error]   |             ^
[error]   |no implicit argument of type Seq[Matchable] => IterableOnce[B] was found for parameter asIterable of method flatten in trait IterableOps
[error]   |
[error]   |where:    B is a type variable with constraint <: String | Int

Expectation

Successful compilation as in 3.0.0 to 3.1.1

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
smartercommented, Feb 21, 2022

/cc @mbovel who’s been on a crusade for less widening 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why isn't the type argument inferred as a union type?
TypeScript in general will not synthesize a union type during generic inference. The reason, in simplified terms, is that it's not desirable ...
Read more >
Infer the type of `x` in `val f: (Int => Int) | Unit = x => x + 1` - GitHub
The argument against doing this for union types in general is efficiency: it requires backtracking. How do we decide which specific cases to...
Read more >
Union Types - More Details - Scala 3
In some situation described below, a union type might need to be widened to a non-union type, for this purpose we define the...
Read more >
Union type widening - Language Design - Scala Contributors
I recently found out about an odd behavior in dotty when using union types. Currently, the compiler widens union types to a common...
Read more >
Handbook - Unions and Intersection Types - TypeScript
Union types can be a bit tricky here, but it just takes a bit of intuition to get used to. If a value...
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