swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.33k forks source link

@MainActor closure type description adds '@Sendable' to the description starting from swift 6 #75683

Open sisoje opened 1 month ago

sisoje commented 1 month ago

Description

When printing type info of @MainActor () -> Void, then, @Sendable is added inside type description when executed in swift 6.

Reproduction

print((@MainActor () -> Void).self) // prints: "@MainActor @Sendable () -> ()" instead of "@MainActor () -> ()"

Expected behavior

'@Sendable' should not be added to the description.

We should have consistent behavior across swift versions, type descriptions should be same in both swift 6 and swift 5.10

Environment

On swift 6.0 its a bug On swift 5.10 works ok

Additional information

No response

MahdiBM commented 1 month ago

We should have consistent behavior across swift versions

Swift 6 is a new major versions. Breaking changes are expected and allowed per SemVer 2.0. A big point of Swift "6" is to be able to release some breaking changes, otherwise there was nothing wrong with the next Swift version being "5.11".

MahdiBM commented 1 month ago

I'm not even sure if string representation of types is considered part of the API (probably not). I can still imagine that the Swift team doesn't want to annoy users by changing descriptions all the time even if they are not considered breaking. But since this is a new major version, such a small change should be fine even after those considerations.

sisoje commented 1 month ago

Basically I can not cast a runtime object to @MainActor ()->() because compiler prevents me by converting it to @MainActor @Sendable ()->() and casting fails. That is an issue. Is it a bug with casting?

Screenshot 2024-08-05 at 10 16 30 PM