Navigation Menu

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-8836] dependent type outside of generic context?! #51343

Closed
swift-ci opened this issue Sep 25, 2018 · 2 comments
Closed

[SR-8836] dependent type outside of generic context?! #51343

swift-ci opened this issue Sep 25, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8836
Radar rdar://problem/44762116
Original Reporter linqingmo (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift Development Snapshot 2018-09-22(a)

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

md5: 790148e6c52362118aeb11ea6887738e

Issue Description:

//
//  JSON.swift
//  HVFoundation
//
//  Created by Harry Lin on 2017/7/24.
//  Copyright © 2017年 heimavista. All rights reserved.
//


import Foundation


public enum JSON {
    case null
    case bool(Bool)
    case number(Double)
    case string(String)
    case array([JSON])
    case dictionary([String: JSON])
    
    public subscript(key: String) -> JSON? {
        get {
            guard case .dictionary(let dictionary) = self else { return nil }
            return dictionary[key]
        }
        set {
            guard case .dictionary(var dictionary) = self else { return }
            dictionary[key] = newValue
            self = .dictionary(dictionary)
        }
    }
}


extension Optional where Wrapped == JSON {
    public subscript(key: String) -> Wrapped? { // public subscript(key: String) -> JSON? is OK
        get {
            return map { $0[key] } ?? nil
        }
        set {
            guard case var wrapped? = self else { return }
            wrapped[key] = newValue
            self = wrapped
        }
    }
}

Assertion failed: ((!key.isDependent() || getCurGenericContext()) && "dependent type outside of generic context?!"), function getTypeLowering, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SIL/TypeLowering.cpp, line 1431.

Why dose it fail to compile?

extension Optional where Wrapped == String {
    public subscript(key: String) -> Wrapped? {
        return nil
    }
}

Why it works?

@belkadan
Copy link
Contributor

Just sounds like a bug.

@swift-ci create

@slavapestov
Copy link
Member

This was fixed a while ago. #21596

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants