Skip to content

Unexpected compiler error when calling value pack-returning function using optional chaining #82487

@Sweeper777

Description

@Sweeper777

Description

When I call a function that returns a value pack using optional chaining, the compiler error "type of expression is ambiguous without a type annotation" is emitted.

Reproduction

class Foo {
    func f<each T>(_ params: repeat each T) -> (repeat each T) { (repeat each params) }
}
func g() {
    let foo: Foo? = Foo()
    let result = foo?.f(1, "", true) // type of expression is ambiguous without a type annotation
}

Expected behavior

No compiler errors are emitted. The type of result should be (Int, String, Bool)?.

Environment

Apple Swift version 6.2-dev (LLVM 0d47fa0a0fd41fb, Swift 536aa93)
Target: arm64-apple-macosx15.0

Additional information

This also happens if I try to use try? to call a throwing function that returns a value pack. This is likely related to the "optionalness" of the whole expression.

Related Stack Overflow question., where the OP attempts to call AVURLAsset.load.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselfexpressionsFeature: expressionsgenericsFeature: generic declarations and typesparameter packsFeature → generics: Parameter packsswift 6.2type checkerArea → compiler: Semantic analysistypealiasFeature → type declarations: `typealias` declarationsunexpected errorBug: Unexpected error

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions