[Regression in 3.1.2-RC1] Inferred union in type argument position gets widened
See original GitHub issueCompiler 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:
- Created 2 years ago
- Comments:17 (17 by maintainers)
Top 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 >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
It is Create fresh type variables to keep constraints level-correct from #14026
/cc @mbovel who’s been on a crusade for less widening 😃