Skip to content

Conversation

noti0na1
Copy link
Member

No description provided.

@noti0na1 noti0na1 requested a review from olhotak August 25, 2025 13:13
@bishabosha
Copy link
Member

bishabosha commented Aug 25, 2025

didnt this already ship in Scala 3.5?

@noti0na1
Copy link
Member Author

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

@noti0na1 noti0na1 marked this pull request as ready for review September 11, 2025 12:26
@noti0na1 noti0na1 self-assigned this Sep 11, 2025
@noti0na1 noti0na1 changed the title SIP-XX - Flexible Types in TASTy format SIP-XX - Adding Flexible Types as Internal Type to Scala 3 Spec Sep 11, 2025
#### 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).
Copy link
Member

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?

Copy link
Member Author

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.

@bracevac bracevac changed the title SIP-XX - Adding Flexible Types as Internal Type to Scala 3 Spec SIP-73 - Adding Flexible Types as Internal Type to Scala 3 Spec Sep 16, 2025

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.
Copy link
Member

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.

Copy link
Member

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)

@odersky
Copy link
Contributor

odersky commented Sep 26, 2025

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 Flex that's inaccessible to users but that is used when we load Java files?

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.

7 participants