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-8295] Data.append(contentsOf: elements) has poor error message. #50823

Closed
Dante-Broggi opened this issue Jul 17, 2018 · 3 comments
Closed
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

@Dante-Broggi
Copy link
Contributor

Previous ID SR-8295
Radar None
Original Reporter @Dante-Broggi
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @Dante-Broggi
Priority Medium

md5: c0f367ff9627a115ed630e3d8228acf5

Issue Description:

When examining #SR-3566, I found it doesn't initialize the sequence it appends to a `Data`

So, I tried to make a sequence, but accidentally made it a sequence of `Int`, not `UInt8`, so it errored. However, it errored with an ambiguity error and not with eg. "Int != UInt8".

So, this is a report of poor compiler error message.

import Foundation
let elements = sequence(first: 1 /* should be "1 as UInt8" */) { _ in 1 }.prefix(5)
var d = Data()
d.append(contentsOf: elements) // Ambiguous reference to member 'append(contentsOf:)'
@belkadan
Copy link
Contributor

   <stdin>:4:1: error: ambiguous reference to member 'append(contentsOf:)'
d.append(contentsOf: elements) 
^
Foundation.Data:48:26: note: found this candidate
    public mutating func append(contentsOf bytes: [UInt8])
                         ^
Foundation.Data:49:37: note: found this candidate
    @inlinable public mutating func append<S>(contentsOf newElements: S) where S : Sequence, S.Element == Data.Iterator.Element
                                    ^
Swift.RangeReplaceableCollection:5:37: note: found this candidate
    @inlinable public mutating func append<S>(contentsOf newElements: S) where S : Sequence, Self.Element == S.Element
                                    ^

cc @xedin

@xedin
Copy link
Member

xedin commented Aug 30, 2018

Errors like that got improved on master, so now it's going to produce following:

error: instance method 'append(contentsOf:)' requires the types 'Int' and 'Data.Iterator.Element' (aka 'UInt8') be equivalent
d.append(contentsOf: elements)
  ^
Foundation.Data:49:37: note: where 'S.Element' = 'Int'
    @inlinable public mutating func append<S>(contentsOf newElements: S) where S : Sequence, S.Element == Data.Iterator.Element
                                    ^

@xedin
Copy link
Member

xedin commented Aug 30, 2018

Thank you for reporting, @Dante-Broggi! Please use the latest nightly snapshot to verify.

@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