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-7177] Strange error when calling popFirst() on Array #49725

Closed
swift-ci opened this issue Mar 12, 2018 · 5 comments
Closed

[SR-7177] Strange error when calling popFirst() on Array #49725

swift-ci opened this issue Mar 12, 2018 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7177
Radar rdar://problem/38394649
Original Reporter helge (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @mdiep
Priority Medium

md5: 2f3c4a9aee6e8a169df6c551de2bf8e3

Issue Description:

Welcome to Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2). Type :help for assistance.
  1> var a = [ 1,2,3,4 ]
a: [Int] = 4 values {
  [0] = 1
  [1] = 2
  [2] = 3
  [3] = 4
}
  2> a.popFirst()
error: repl.swift:2:1: error: cannot use mutating member on immutable value: 'a' is immutable
a.popFirst()
^

I don't know, but something is going wrong here. `a` is obviously mutable.

@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Fred Riss (JIRA)

> cat arr.swift
var a = [1,2,3,4]
var b = a.popFirst()
Locals-iMac-Pro-3:/tmp > swiftc -g -Onone arr.swift
arr.swift:2:9: error: cannot use mutating member on immutable value: 'a' is immutable
var b = a.popFirst()
^

It does seem to me odd that a is not considered a mutable array, but it's not special to the REPL.

@belkadan
Copy link
Contributor

Ah, it's just a completely wrong diagnostic. Thanks, Fred.

@mdiep
Copy link
Contributor

mdiep commented Jun 5, 2018

This now gives the correct diagnostic:

error: '[Int]' requires the types '[Int]' and 'ArraySlice<Int>' be equivalent to use 'popFirst'
var b = a.popFirst()
          ^

Although that would ideally explain that popFirst is defined in an extension where SubSequence == Self.

@mdiep
Copy link
Contributor

mdiep commented Jul 6, 2018

The diagnostic has been improved in #17210

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

No branches or pull requests

3 participants