Files
swift-mirror/test/stmt/c_style_for.swift
Hamish Knight abf0808173 [Sema] Continue type-checking for body when preamble fails
Skipping type-checking the body when the preamble fails to type-check
seems to be more of a historical artifact than intentional behavior.
Certain elements of the body may still get type-checked through
request evaluation, and as such may introduce autoclosures that won't
be properly contextualized. 

Make sure we continue type-checking the body even if the preamble
fails. We already invalidate any variables bound in the element
pattern, so downstream type-checking should be able to handle it
just fine. This ensures autoclosures get contextualized, and that
we're still able to provide semantic diagnostics for other issues in
the body.

rdar://136500008
2025-05-15 21:23:40 +01:00

41 lines
1.5 KiB
Swift

// RUN: %target-typecheck-verify-swift
for var i = 0; i < 10; i++ {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 0; i < 10; i += 1 {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 0; i <= 10; i++ {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 0; i <= 10; i += 1 {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 10; i > 0; i-- {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 10; i > 0; i -= 1 {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 10; i >= 0; i-- {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
for var i = 10; i >= 0; i -= 1 {}
// expected-error @-1 {{C-style for statement was removed in Swift 3}} {{none}}
let start = Int8(4)
let count = Int8(10)
var other = Int8(2)
for ; other<count; other+=1 { // expected-error {{C-style for statement was removed in Swift 3}} {{none}}
}
for (var number : Int8 = start; number < count; number+=1) { // expected-error {{C-style for statement was removed in Swift 3}} {{none}}
print(number) // expected-error {{cannot find 'number' in scope}}
}
for (var m : Int8 = start; m < count; m+=1) { // expected-error {{C-style for statement was removed in Swift 3}} {{none}}
m += 3 // expected-error {{cannot find 'm' in scope}}
}