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-10263] Compile error when generic function with where clause is called on weak variable. #52663

Open
swift-ci opened this issue Apr 2, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 2, 2019

Previous ID SR-10263
Radar None
Original Reporter maciek2w@gmail.com (JIRA User)
Type Bug
Environment

Reproduced on:

  • Xcode 10.2 Swift 5

  • Swift-4.2.1

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

md5: eec2bcf4fac3d33b4daaa8c1e24287c3

Issue Description:

Got error "cannot convert value of type '[Base.Type]' to expected argument type '[_.Type]'"
when generic function with `where` clause is called on weak variable.

import Foundation

// Lets create base class and two classes that inherits base class.
class Base {}
class A: Base {}
class B: Base {}

// Lets create class with generic function with `where` clauses
class Printer {
    func printAll<T>(classes: [T.Type]) where T: Base {
        for c in classes {
            print(String(describing: c))
        }
    }
}

// Lets create the instance
let printer = Printer()

// Compiles
printer.printAll(classes: [A.self, B.self])

// Lets create weak variable
weak var weakPrinter: Printer! = printer

// Compiles
weakPrinter.printAll(classes: [A.self])

// Does not compile with error:
// "cannot convert value of type '[Base.Type]' to expected argument type '[_.Type]'"
weakPrinter.printAll(classes: [A.self, B.self])
@belkadan
Copy link
Contributor

belkadan commented Apr 2, 2019

Hm. Explicitly specifying as [Base.Type] makes everything work, so there must be something weird going on in the type checker. cc @xedin

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants