Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion returns empty result in result builder else if block #79213

Closed
hamishknight opened this issue Feb 7, 2025 · 1 comment · Fixed by #79217 or swiftlang/swift-source-compat-suite#975
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion found by stress tester Flag: An issue found by the SourceKit stress tester SourceKit Area → source tooling: SourceKit

Comments

@hamishknight
Copy link
Contributor

hamishknight commented Feb 7, 2025

The following returns no completion results:

import SwiftUI

struct R {
  var bar: Bool
}

func baz<R>(@ViewBuilder _ fn: () -> R) -> R { fn() }

func foo(_ x: R, _ b: Bool) -> some View {
  baz {
    if b {
      EmptyView()
    } else if !b {
      if x.#^CC^# {}
    }
  }
}

Swift version 6.2-dev (LLVM 496a44abf299a10, Swift c35d65e)
Target: arm64-apple-macosx15.0

@hamishknight hamishknight added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion found by stress tester Flag: An issue found by the SourceKit stress tester SourceKit Area → source tooling: SourceKit labels Feb 7, 2025
@hamishknight hamishknight self-assigned this Feb 7, 2025
@hamishknight
Copy link
Contributor Author

Without SwiftUI:

protocol View {}

struct EmptyView: View {}
struct Either<T: View, U: View>: View {}
struct Tuple<T>: View {}
extension Optional: View where Wrapped: View {}

@resultBuilder
struct ViewBuilder {
  static func buildBlock() -> EmptyView { .init() }
  static func buildBlock<T: View>(_ x: T) -> T { x }
  @_disfavoredOverload static func buildBlock<each T: View>(
    _ x: repeat each T
  ) -> Tuple<(repeat each T)> { .init() }
  static func buildEither<T, U>(first component: T) -> Either<T, U> { .init() }
  static func buildEither<T, U>(second component: U) -> Either<T, U> { .init() }
  static func buildIf<T: View>(_ x: T?) -> T? { x }
}

struct R {
  var bar: Bool
}

func baz<R>(@ViewBuilder _ fn: () -> R) {}

func foo(_ x: R, _ b: Bool) {
  baz {
    if b {
      EmptyView()
    } else if b {
      if x.#^CC^# {}
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion found by stress tester Flag: An issue found by the SourceKit stress tester SourceKit Area → source tooling: SourceKit
Projects
None yet
1 participant