mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We already had bookkeeping to track which statement in a multi-statement closure we were looking at, but this was only used for the 'reasonable time' diagnostic in the case that we hit the expression timer, which was almost never hit, and is now off by default. The scope, memory, and trial limits couldn't use this information, so they would always diagnose the entire target being type checked. Move it up from ExpressionTimer to ConstraintSystem, so that we get the right source location there too. Also, factor out some code duplication in BuilderTransform to ensure we get the same benefit for result builders applied to function bodies too.
44 lines
1.3 KiB
Swift
44 lines
1.3 KiB
Swift
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
|
|
// REQUIRES: objc_interop
|
|
|
|
// https://forums.swift.org/t/roadmap-for-improving-the-type-checker/82952/9
|
|
//
|
|
// The purpose of the test is to ensure the diagnostic points at the right statement in
|
|
// the function body, and not the function declaration itself.
|
|
//
|
|
// Ideally, we would produce a useful diagnostic here. Once we are able to do that, we
|
|
// will need to devise a new test which complains with 'reasonable time' to ensure the
|
|
// source location remains correct.
|
|
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@State var selection = ""
|
|
|
|
@State var a: Int?
|
|
@State var b: Int?
|
|
@State var c: Int?
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack {
|
|
Picker(selection: $selection) {
|
|
ForEach(["a", "b", "c"], id: \.self) {
|
|
Text($0) // expected-error {{reasonable time}}
|
|
.foregroundStyl(.red) // Typo is here
|
|
}
|
|
} label: {
|
|
}
|
|
.pickerStyle(.segmented)
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
.onChange(of: a) { oldValue, newValue in
|
|
}
|
|
.onChange(of: b) { oldValue, newValue in
|
|
}
|
|
.onChange(of: c) { oldValue, newValue in
|
|
}
|
|
}
|
|
}
|