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-14559] Compiler Crash Combining Result Builder with Scoped Type Alias #56911

Open
swift-ci opened this issue Apr 30, 2021 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14559
Radar rdar://problem/77465733
Original Reporter juliand665 (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 12.5, macOS 11.3

Also tested with Swift 5.5 Development Snapshot from 2021-04-20.

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

md5: abcfd4bd21989fb758c8323471ae9957

Issue Description:

When a result builder is applied to a protocol requirement, it is automatically applied for any conformers. However, this automatic application fails if the builder involves a typealias scoped to the protocol in question:

@resultBuilder
struct Builder<T> {
    static func buildExpression(_ expression: T) -> [T] {
        [expression]
    }
    
    static func buildBlock(_ components: [T]...) -> [T] {
        Array(components.joined())
    }
}

typealias OutsideString = String
typealias OutsideStringBuilder = Builder<String>

protocol Buildable {
    typealias InsideString = String
    typealias InsideStringBuilder = Builder<String>
    
    // these crash:
    //@Builder<InsideString>
    //@InsideStringBuilder
    
    // these work fine:
    //@OutsideStringBuilder
    //@Builder<OutsideString>
    //@Builder<String>
    
    func build() -> [String]
}

struct Building: Buildable {
    // at this site they all work; just using this as an example
    @InsideStringBuilder
    func build() -> [String] {
        "foo"
        "bar"
    }
}

There are comments in the code snippet for more information. The crash occurs when any type alias is involved in the annotation, whether as a generic parameter (@Builder<InsideString>) or as the type itself (@InsideStringBuilder).

The crash does not occur if you don't declare a type implementing that member or if you override the builder (explicitly specifying it) for that member in the conforming type.

I've attached a build log exhibiting the crash.

@typesanitizer
Copy link

@swift-ci create

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

No branches or pull requests

2 participants