Skip to content
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

Update examples in 0458-strict-memory-safety.md #2661

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

natecook1000
Copy link
Member

This change addresses two examples:

  1. The text introducing the updated version of the sum() example is "The warning-free version of this code is:", but the code sample still includes the warning. This change removes the warning.

  2. The swapAt implementation has two issues:

  • the parameters should be of type Index (or Int?), not Element
  • the precondition check that i and j are before endIndex should not have an unsafe keyword, since endIndex is designated as @safe.

Fix some errors in the examples
guard i != j else { return }
precondition(i >= 0 && j >= 0)
precondition(unsafe i < endIndex && j < endIndex)
precondition(i < endIndex && j < endIndex)
Copy link
Member

Choose a reason for hiding this comment

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

According to the current proposal, the unsafe is needed with the endIndex because of the implicit self being of an unsafe type. There is discussion on the review thread about how we might avoid that.

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