Skip to content

[SR-9043] Missing checks of inout/mutating captures #51546

@swift-ci

Description

@swift-ci
Previous ID SR-9043
Radar rdar://problem/45511834
Original Reporter koher (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 10.0 (10A255)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @slavapestov
Priority Medium

md5: 23f0e6aa3983c486dcd3930dc0b1232d

relates to:

  • SR-8546 Enforce @escaping for for all but the most trivial uses of captured variables.

Issue Description:

The following code causes a compile-time error correctly.

func run(_ body: @escaping () -> Void) { body() }


struct S {
    var a: Int = 3
    
    mutating func foo() {
        func _foo() {
            if a == 0 { return }
            a -= 1
            print(a)
            run(_foo)
        }
        _foo()
    }
}


var s = S()
s.foo()
error: nested function with an implicitly captured inout parameter can only be used as a non-escaping argument
             run(_foo)
             ^

However, when `run(_foo)` is changed to `run { _foo() }`, it can be compiled. I guess the compiler lacks some checks.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaretype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions