-
Notifications
You must be signed in to change notification settings - Fork 29
SIP-73 - Adding Flexible Types as Internal Type to Scala 3 Spec #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
didnt this already ship in Scala 3.5? |
The implementation has been shipped. The core team is asking for a SIP to finalize the tag in TASTy. See the discussion at: scala/scala3#23682 |
#### Type Erasure (Extension to §3.8) | ||
|
||
The erased type of `T?` is the erased type of the underlying type `T`. | ||
Erasure is extended with: `|T?| = |T|` (i.e., identical to the erasure of its underlying type). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if T
is Int
, or any other really-non-nullable primitive type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the Type Erasure section to explain the choice.
|
||
They may appear in type signatures because of type inference. | ||
Due to their non-denotable nature, we do not recommend exposing Flexible Types in public APIs or library interfaces. | ||
We have implemented a mechanism to warn users when Flexible Types are exposed at public (or protected) field or method boundaries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be good if the SIP could describe in more detail this warning mechanism and other situations where users might be confronted with flexible types. Ideally with a comparison to how platform types are handled in Kotlin since they have a similar nature and I assume have had time to get a polished user experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(or maybe this comes up in the follow-up explicit nulls SIP, not sure where to draw the line)
Do we really need flexible types as a separate form of type? I can do this: type Flex[T] >: T | Null <: T
var x: Flex[String] = null
x = "abc"
val y = x.length
val s: String = x The only error I get is that type Flex has conflicting bounds. If I suppress that error, everything compiles fine. So, can we make do with just defining a type like |
No description provided.