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-10932] Incorrect Error Description For Substrings #53323

Closed
swift-ci opened this issue Jun 15, 2019 · 3 comments
Closed

[SR-10932] Incorrect Error Description For Substrings #53323

swift-ci opened this issue Jun 15, 2019 · 3 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement standard library Area: Standard library umbrella type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10932
Radar None
Original Reporter bdkjones (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler, Standard Library
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 273026d096d5ee94205038b5afcf8de9

relates to:

  • SR-12703 Another Occurrence of the Misleading Error Message "subscript 'subscript(_:)' requires the types 'String.Index' and 'Int' be equivalent"

Issue Description:

Given this code:

let rawString = "Some String"
let idx = rawString.firstIndex(of: "t")!

let good: String = String(rawString[idx...])   // OK
let bad: String = rawString[idx...]            // ERROR

Xcode 11 and Swift 5.1 present the following error to the user on the line marked with "// ERROR":

Subscript 'subscript(_:)' requires the types 'String.Index' and 'Int' be equivalent

This error is worse than useless because it not only does nothing to inform the user what the problem is (the Substring must be converted back to String), it leads them down the wrong path when searching Stack Overflow.

The compiler should provide a much better error message in this case.

@belkadan
Copy link
Contributor

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator

This seems fixed, on master the diagnostics produced are

let rawString = "Some String"
let idx = rawString.firstIndex(of: "t")!

let good: String = String(rawString[idx...])   // OK
let bad: String = rawString[idx...]            // error: cannot convert value of type 'String.SubSequence' (aka 'Substring') to specified type 'String'

bdkjones (JIRA User) Can you please verify using the latest nightly snapshot and resolve this 🙂
cc @xedin

@marcomasser
Copy link

I verified that this is fixed using Swift 5.2.2. But there’s still another case where this error message shows: SR-12703.

@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
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement standard library Area: Standard library umbrella type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants