Skip to content

Conversation

@mbovel
Copy link
Member

@mbovel mbovel commented Feb 1, 2022

Hard unions are union types explicitly written by the user, while soft unions are created by the compiler (for example as the result of a condition or a match). The former should not be widened, while the later should. Currently, this does not work if the union's operands are singletons because the union looses its "hardness" qualification. This PR fixes it.

Before:

val x: Int | String = 3
val y /* : Int | String */ = x
val x2: 3 | "a" = 3
val y2 /* : Matchable */ = x2

After:

val x: Int | String = 3
val y /* : Int | String */ = x
val x2: 3 | "a" = 3
val y2 /* --> : Int | String <-- */ = x2

#14347 and #14360 are linked but have a wider scope: avoiding to widen explicit singleton types altogether. But these are not conclusive yet.

@mbovel mbovel marked this pull request as draft February 1, 2022 18:47
@mbovel mbovel requested a review from dwijnand February 1, 2022 21:58
@mbovel mbovel marked this pull request as ready for review February 1, 2022 23:23
@mbovel mbovel requested a review from smarter February 2, 2022 10:21
@dwijnand dwijnand merged commit e5c8238 into scala:main Feb 2, 2022
@dwijnand dwijnand deleted the mb/singletons-in-hard-unions branch February 2, 2022 15:20
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants