Skip to content

[SR-15286] Expression type checks as standalone but is ambiguous inside result builder #57608

@ahoppen

Description

@ahoppen
Previous ID SR-15286
Radar rdar://83929254
Original Reporter @ahoppen
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: f7a7fb45fba6ec59908fe7403ab7acf2

Issue Description:

When typechecking the following, the first call of TokenWrapper(token: .test) type checks fine, but the call inside the result builder later on fails with an error message Type of expression is ambiguous without more context.

protocol ExpressibleAsTokenSyntax {}

struct TokenSyntax: ExpressibleAsTokenSyntax {}

extension ExpressibleAsTokenSyntax where Self == TokenSyntax {
  static var test: TokenSyntax { TokenSyntax() }
}

struct TokenWrapper {
  init(token: ExpressibleAsTokenSyntax) {}
}

@resultBuilder
struct MyBuilder {
  public static func buildBlock(_ components: TokenWrapper...) -> TokenWrapper {
    return components.first!
  }
}

func build(@MyBuilder builder: () -> TokenWrapper) {}

// This compiles
TokenWrapper(token: .test)

// But this fails: Type of expression is ambiguous without more context
build {
  TokenWrapper(token: .test)
}

Happens in both Swift 5.5 and swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions