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

[SR-982] String sort order and comparisons differ between Darwin and Linux #43594

Closed
swift-ci opened this issue Mar 18, 2016 · 5 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-982
Radar rdar://problem/19686029
Original Reporter jaybuff (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee Lance (JIRA)
Priority Medium

md5: 35a3933b0e54b26296ac7ab562247da5

Issue Description:

Under macos ("a"..."z").contains("J") returns false:

$ uname -a
Darwin lyra 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64

$ swift
Welcome to Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38). Type :help for assistance.
  1>  ("a"..."z").contains("J")
$R0: Bool = false
  2> ^D

Under linux it returns true:

$ uname -a
Linux default 4.4.17-boot2docker #​1 SMP Mon Aug 15 17:12:38 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ swift
Welcome to Swift version 3.0 (swift-3.0-PREVIEW-4). Type :help for assistance.
  1>  ("a"..."z").contains("J")
$R0: Bool = true
  2> ^D
@kevints
Copy link
Mannequin

kevints mannequin commented Oct 21, 2016

Looks like the behavior on Linux is correct according to TR10:

http://unicode.org/reports/tr10/#Multi_Level_Comparison

In Unicode collation order "J" should sort before "z" and after "a" so this return value is consistent with the documentation.

@alblue
Copy link
Contributor

alblue commented Oct 24, 2016

The implementation on Darwin uses a hack if the elements are ASCII to use normal ASCII conventions, which results in this behaviour. It seems that this optimisation has caused problems elsewhere as well:

ef974af

I wonder if the right thing to do is to ditch the hack altogether and have consistent behaviour on all platforms.

@swift-ci
Copy link
Collaborator Author

Comment by Jay Buffington (JIRA)

Another example:

# on Darwin
  1> ["A", "b", "C", "d"].sorted(by: { $0 < $1 })
$R0: [String] = 4 values {
  [0] = "A"
  [1] = "C"
  [2] = "b"
  [3] = "d"
}


# On Linux
  1> ["A", "b", "C", "d"].sorted(by: { $0 < $1 })
$R0: [String] = 4 values {
  [0] = "A"
  [1] = "b"
  [2] = "C"
  [3] = "d"
}

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 28, 2018

This should've been fixed with #13877

Lance (JIRA User) can you verify set to resolve if so?

edit: Terminology surrounding "verify" and "resolve", grammar

@milseman
Copy link
Mannequin

milseman mannequin commented May 25, 2018

This was fixed for 4.2

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants