Skip to content

SourceLocation.init should enforce valid arguments #817

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

Merged

Conversation

stmontgomery
Copy link
Contributor

This modifies SourceLocation.init() to add preconditions which enforce that its arguments are valid, matching preconditions in the corresponding properties.

Modifications:

  • Add preconditions to the initializer which match those in didSet of the corresponding properties.
  • Add precondition DocC symbol documentation where relevant.
  • Adjusted existing tests which were previously invalid (although not particularly problematic) but were not failing.

Result:

Newly-added exit tests now pass.

Checklist:

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

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@@ -51,21 +51,6 @@ struct SourceLocationTests {
#expect(sourceLocation.fileName == "D.swift")
}


#if !SWT_NO_EXIT_TESTS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved this down without modification, to consolidate several exit tests together

Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

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

We should consider adding comments to all the precondition() calls since they don't do source capture, e.g.:

precondition(line > 0, "SourceLocation.line must be greater than 0 (was \(line))")

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit 8b3632a into swiftlang:main Nov 11, 2024
3 checks passed
@stmontgomery stmontgomery deleted the source-location-preconditions branch November 11, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants