Skip to content

Implement an overload of confirmation() that takes an unbounded range. #598

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 2, 2024

Unbounded ranges are not meaningful when used with confirmation() because any confirmation count matches. As well, the ... operator produces an instance of UnboundedRange which is a non-nominal type and cannot conform to RangeExpression. It may be non-obvious to a developer why ... doesn't work as the expectedCount argument to that function when other range operators work as expected.

This PR implements a stub overload of confirmation() that takes an unbounded range. The stub overload is marked unavailable and cannot be called.

Example usage:

await confirmation("Stuff happens", expectedCount: ...) { stuff in
  // ...
}

Generated diagnostic:

🛑 'confirmation(_:expectedCount:sourceLocation:_:)' is unavailable: Unbounded range '...' has no effect when used with a confirmation.

As a reminder, using a range expression with confirmation() is an experimental feature and has not been API-reviewed.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

Unbounded ranges are not meaningful when used with `confirmation()` because
_any_ confirmation count matches. As well, the `...` operator produces an
instance of `UnboundedRange` which is a non-nominal type and cannot conform to
`RangeExpression`. It may be non-obvious to a developer why `...` doesn't work
as the `expectedCount` argument to that function when other range operators work
as expected.

This PR implements a stub overload of `confirmation()` that takes an unbounded
range. The stub overload is marked unavailable and cannot be called.
@grynspan grynspan added enhancement New feature or request public-api Affects public API labels Aug 2, 2024
@grynspan grynspan self-assigned this Aug 2, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Aug 2, 2024

@swift-ci please test

@@ -188,7 +188,7 @@ enum Environment {
return nil
case let errorCode:
let error = Win32Error(rawValue: errorCode)
fatalError("unexpected error when getting environment variable '\(name)': \(error) (\(errorCode))")
fatalError("Unexpected error when getting environment variable '\(name)': \(error) (\(errorCode))")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by formatting tweak.

@@ -118,7 +118,7 @@ private func _createAvailabilityTraitExpr(
return ".__unavailable(message: \(message), sourceLocation: \(sourceLocationExpr))"

default:
fatalError("Unsupported keyword \(whenKeyword) passed to \(#function)")
fatalError("Unsupported keyword \(whenKeyword) passed to \(#function). Please file a bug report at https://github.com/swiftlang/swift-testing/issues/new")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by amendment to fatal error message.

@grynspan
Copy link
Contributor Author

grynspan commented Aug 6, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

Self-reviewing (tsk.)

@grynspan grynspan changed the base branch from main to main-next August 21, 2024 00:22
@grynspan grynspan merged commit bba4bdf into main-next Aug 21, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/unbounded-range-confirmation branch August 21, 2024 00:22
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant