Files
swift-mirror/test/Constraints/rdar65320500.swift
Pavel Yaskevich 4b0d9a2509 [ResultBuilders] Diagnose pre-check errors inline
Not all of the pre-check errors could be diagnosed by re-running
`PreCheckExpression` e.g. key path expressions are mutated to
a particular form after an error has been produced.

To make the behavior consistent, let's allow pre-check to emit
diagnostics and unify pre-check and constraint generation fixes.

Resolves: rdar://77466241
2021-05-10 11:06:58 -07:00

44 lines
831 B
Swift

// RUN: %target-typecheck-verify-swift
struct Result {}
@resultBuilder
struct Builder {
static func buildBlock() -> Result {
Result()
}
}
func test_builder<T>(@Builder _: () -> T) {}
func test_builder(@Builder _: () -> Int) {}
test_builder {
let _ = 0
if let x = does_not_exist { // expected-error {{cannot find 'does_not_exist' in scope}}
}
}
func test(_: Int) -> Bool {
return false
}
test_builder {
let totalSeconds = 42000 // expected-note {{'totalSeconds' declared here}}
test(totalseconds / 3600) // expected-error {{cannot find 'totalseconds' in scope; did you mean 'totalSeconds'?}}
}
test_builder {
test(doesntExist()) // expected-error {{cannot find 'doesntExist' in scope}}
if let result = doesntExist() {
}
if bar = test(42) {}
let foo = bar()
switch (doesntExist()) {
}
}