Skip to content

Typechecker does not propagate effects correctly on Windows #82236

Open
@jmschonfeld

Description

@jmschonfeld

Description

Given the following test:

func foo(_: () throws -> Void) {}
func throwing() throws -> Bool { true }

@Test func issue() throws {
    foo {
        #expect(try throwing())
    }
}

This builds successfully on macOS and Linux, but on Windows it fails to build with the following error:

macro expansion #expect:1:22: error: errors thrown from here are not handled
`- C:\Users\[...]:776:36: note: expanded code originates here
 774 |     @Test func issue() throws {
 775 |         foo {
 776 |             #expect(try throwing())
     |             `- note: in expansion of macro 'expect' here
     +--- macro expansion #expect --------------------------------------
     |1 | Testing.__checkValue(try throwing(),expression: .__fromSyntaxNode("try throwing()"),comments: [],isRequired: false,sourceLocation: Testing.SourceLocation.__here()).__expected()
     |  |                      `- error: errors thrown from here are not handled
     +------------------------------------------------------------------
 777 |         }
 778 |     }
error: fatalError

However, if you insert try throwing() in the closure before #expect or if you change foo { to foo { () throws in, then the compiler builds the test successfully.

Reproduction

(see above)

Expected behavior

Expected to compile consistently across all platforms

Environment

Swift version 6.2-dev (LLVM d266fd9f80a7945, Swift 665515c)
Target: aarch64-unknown-windows-msvc
Build config: +assertions

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsthrows & rethrowsFeature → error handling: throws & rethrowstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions