Files
swift-mirror/test/SourceKit/CodeComplete/sr14430.swift
Alex Hoppen 6085e1dca4 [CodeCompletion] Reset diagnostics when reusing an ASTContext for completion
The diagnosticc engine is keeping track of state which might modify parsing/typechecking behaviour. In the added test case the `fatalErrorOccurred` flag was during the first completion. The flag was still `true` for the second completion, causing parsing/typechecking to behave slightly differently. Because of this, the ExprRewriter failed when applying a constraint system solution, not properly cleaning up its `ExprStack`.

This PR tackles both issues:
1) Reset the `hadError` flags in the diagnostics engine
2) Clean up the `ExprRewriter`’s `ExprStack` when rewriting a target fails.

Either of these changes fixes the crash in the test case but I think both could manifest through different code paths in different scenarios.

Fixes rdar://76051976 [SR-14430]
2021-04-15 13:07:27 +02:00

52 lines
1.3 KiB
Swift

// Check that we are not crashing
// RUN: %sourcekitd-test -req=complete -pos=48:28 %s -- %s == -req=complete -pos=48:16 %s -- %s
let abcde = "abc"
public struct MyEmptyView : MyView {
public typealias Body = Never
public var body: Never { fatalError() }
}
extension Never : MyView {}
@resultBuilder public struct MyViewBuilder {
public static func buildBlock() -> MyEmptyView {
return MyEmptyView()
}
public static func buildBlock<Content>(_ content: Content) -> Content where Content : MyView {
content
}
}
public protocol MyView {
associatedtype Body : MyView
@MyViewBuilder var body: Self.Body { get }
}
public struct MyHStack<Content> : MyView {
public init(@MyViewBuilder content: () -> Content) {}
public typealias Body = Swift.Never
public var body: Never { fatalError() }
}
public struct MyText : MyView {
public init(_ content: Swift.String) {}
public typealias Body = Never
public var body: Never { fatalError() }
}
extension MyView {
public func padding(_ insets: Bool) -> some MyView { return MyEmptyView() }
public func padding(_ length: Float) -> some MyView { return MyEmptyView() }
public func padding() -> some MyView { return MyEmptyView() }
}
struct RoundedBadge : MyView {
var body: some MyView {
MyHStack {
MyText(abcde).padding()
}
}
}