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-985] Nested generic type in function is not allowed #43597

Closed
an0 mannequin opened this issue Mar 19, 2016 · 1 comment
Closed

[SR-985] Nested generic type in function is not allowed #43597

an0 mannequin opened this issue Mar 19, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@an0
Copy link
Mannequin

an0 mannequin commented Mar 19, 2016

Previous ID SR-985
Radar None
Original Reporter @an0
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: f3e4c0c6558ec266c5547d7f7e079fa3

Issue Description:

This code runs in playground but repl and swiftc reports error:

type 'Stack' nested in generic function 'foo' is not allowed

func foo() {
    class Stack<Element> {
        init() {
            array = []
        }
        init(e: Element) {
            array = [e]
        }
        init<S: Sequence where S.Iterator.Element == Element>(es: S) {
            array = [Element](es)
        }
        var array: [Element]
        func push(_ e: Element) {
            array.append(e)
        }
        func push<S: Sequence where S.Iterator.Element == Element>(_ es: S) {
            array.append(contentsOf: es)
        }
        func pop() -> Element? {
            return array.popLast()
        }
        var isEmpty: Bool {
            return array.isEmpty
        }
    }
    
    func tailRecursive(_ stack: Stack<Int>) {
        guard let i = stack.pop() else { return }
        print(i)
        stack.push(i + 1)
        tailRecursive(stack)
    }
    
    tailRecursive(Stack(e: 0))
}

foo()
@an0
Copy link
Mannequin Author

an0 mannequin commented Jul 19, 2016

Fixed in Swift 3

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

No branches or pull requests

0 participants