Skip to content

Commit 1038493

Browse files
committed
[Tests] NFC: Add a test-case for invalid optional promotion
1 parent 7654afd commit 1038493

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/Constraints/optional.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,19 @@ do {
598598
test(x!) // expected-error {{no exact matches in call to local function 'test'}}
599599
// expected-error@-1 {{cannot force unwrap value of non-optional type 'Double'}}
600600
}
601+
602+
// Diagnose cases of invalid chaining when parameter is not optional based on context.
603+
do {
604+
class Test {
605+
var value: Int = 42
606+
}
607+
608+
class Container {
609+
let test: Test = Test()
610+
611+
func loop() {
612+
[test].forEach { $0?.value = 42 }
613+
// expected-error@-1 {{cannot use optional chaining on non-optional value of type 'Test'}}
614+
}
615+
}
616+
}

0 commit comments

Comments
 (0)