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-11702] Misleading Error Message "Subscript 'subscript(_: )' requires the types 'String.Index' and 'Int' be equivalent" #54110

Closed
swift-ci opened this issue Nov 2, 2019 · 3 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 2, 2019

Previous ID SR-11702
Radar None
Original Reporter cocoanetics (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI
Assignee None
Priority Medium

md5: 265d39699983fb138f48fa2a0e4a8417

relates to:

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

Issue Description:

Paste the following into a playground:

import Foundation
{{ }}
var string = "something;"{{ }}
if let index = string.firstIndex(of: ";")
{{ string = string[..<index]}}{{ }}
{{}}}

You get a misleading error message:

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

Really the reason for the error is that you cannot assign a Substring to a String and the error message should say that.

@theblixguy
Copy link
Collaborator

This diagnostic has been improved on master:

/Users/suyashsrijan/Desktop/test.swift:5:18: error: cannot assign value of type 'String.SubSequence' (aka 'Substring') to type 'String'
  string = string[..<index]
           ~~~~~~^~~~~~~~~~
           String(         )

@theblixguy
Copy link
Collaborator

You can verify using the latest development snapshot 🙂 (please don't forget to close the ticket after that)

@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
Projects
None yet
Development

No branches or pull requests

3 participants