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-3236] Bogus diagnostics for referencing ".init" on instances #45824

Closed
rintaro mannequin opened this issue Nov 18, 2016 · 5 comments
Closed

[SR-3236] Bogus diagnostics for referencing ".init" on instances #45824

rintaro mannequin opened this issue Nov 18, 2016 · 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

@rintaro
Copy link
Mannequin

rintaro mannequin commented Nov 18, 2016

Previous ID SR-3236
Radar None
Original Reporter @rintaro
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 3.0-dev (LLVM 6036ececa5, Clang fdf2d778a7, Swift 81f9fa2)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @rintaro
Priority Medium

md5: 1e23637915cfc9b6725e08a4d511d7cb

relates to:

  • SR-2484 Bad diagnostic for incorrectly calling private init
  • SR-3245 Misplaced fix-it for referencing ".init" on instances

Issue Description:

This is not a problem in 3.0.1.
Only on the master.

Compiling:

let a = [1,2,3]
a.init()

emits:

test.swift:2:1: error: 'Array<Element>' initializer is inaccessible due to 'internal' protection level
a.init()
^
<unknown>:0: note: 'init(_buffer:)' declared here
Swift.Array<Element>:15:12: note: 'init(arrayLiteral:)' declared here
    public init(arrayLiteral elements: Element...)
           ^
Swift.Array<Element>:14:12: note: 'init()' declared here
    public init()
           ^
Swift.Array<Element>:49:12: note: 'init' declared here
    public init<S>(_ s: S) where S : Sequence, Element == S.Iterator.Element
           ^
Swift.Array<Element>:64:12: note: 'init(repeating:count:)' declared here
    public init(repeating repeatedValue: Element, count: Int)
           ^
<unknown>:0: note: 'init(_uninitializedCount:)' declared here
<unknown>:0: note: 'init(count:repeatedValue:)' declared here
Swift.RangeReplaceableCollection:17:24: note: 'init(repeating:count:)' declared here
    public convenience init(repeating repeatedValue: Self.Iterator.Element, count: Int)
                       ^
Swift.RangeReplaceableCollection:22:24: note: 'init' declared here
    public convenience init<S>(_ elements: S) where S : Sequence, Self.Iterator.Element == S.Iterator.Element
                       ^

I confirmed this does happen on Array, Dictionary, Set or AnyIterator.
and does not happen for String, Range.

@belkadan
Copy link
Contributor

To be clear, it should be an error to access init on an instance.

@jtbandes
Copy link
Collaborator

Improving this in #5869

@rintaro
Copy link
Mannequin Author

rintaro mannequin commented Nov 19, 2016

@jtbandes Thank you for working on this!

I've posted a new SR related to this SR. [SR-3245].
Sorry, I should have explicitly written expected results.
Actually, my expectation is improved version of SR-3245.

a.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{1-1=type(of: }} {{2-2=)}}

@jtbandes
Copy link
Collaborator

I believe my fix from #5869 resolves this issue. However, SR-3245 still remains.

The diagnostics from your example are now:

error: 'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type
a.init()
^
  type(of:  )

@rintaro
Copy link
Mannequin Author

rintaro mannequin commented Nov 25, 2016

Confirmed it's fixed. Thank you!

@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

2 participants