Skip to content

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 25, 2024

No description provided.

@ahoppen ahoppen requested a review from bnbarham July 25, 2024 21:11
@ahoppen
Copy link
Member Author

ahoppen commented Jul 25, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2024

@swift-ci Please test Windows

@ahoppen ahoppen requested a review from hamishknight July 26, 2024 00:19
Comment on lines 111 to 125
if Mirror(reflecting: value).displayStyle == .optional && String(describing: value) == "nil" {
// This is the best way I have found of figuring out if a value of type `Any` is `nil`.
return "nil"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative is introducing a protocol you can cast to, e.g:

protocol _OptionalProtocol {
  associatedtype Wrapped
  var _asOptional: Wrapped? { get }
}
extension Optional: _OptionalProtocol {
  var _asOptional: Wrapped? { self }
}

let x = Int?.none as Any
if let y = x as? any _OptionalProtocol {
  print(y._asOptional == nil) // true
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@ahoppen
Copy link
Member Author

ahoppen commented Jul 26, 2024

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Jul 29, 2024

@swift-ci Please test

@ahoppen ahoppen merged commit 1ccafcc into swiftlang:main Jul 30, 2024
@ahoppen ahoppen deleted the log-options branch July 30, 2024 01:48
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.

2 participants