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

[SR-14377] Fallback Diagnostic When Switch Subject Doesn't Typecheck in Result Builder #56735

Open
CodaFi opened this issue Mar 20, 2021 · 2 comments
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis

Comments

@CodaFi
Copy link
Member

CodaFi commented Mar 20, 2021

Previous ID SR-14377
Radar rdar://problem/75656299
Original Reporter @CodaFi
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, TypeChecker
Assignee None
Priority Medium

md5: bc2147bc8ad95debb7c0b5d28a624389

Issue Description:

This code emulates the following construct in SwiftUI, which produces a fallback diagnostic in 12E5244e.

enum SomeEnum {
  case someCase
}

struct MyView: View {
  var klass: SomeEnum

  var body: some View {
    ZStack {
      switch self. {
      case .someCase:
        EmptyView()
      }
    }
  }
}

But does not require the SwiftUI dependency

enum Either<T, U> {
  case first(T)
  case second(U)
}

@resultBuilder
struct TupleBuilder {
  static func buildBlock() -> () { }

  static func buildEither<T: Tuple, U: Tuple>(first value: T) -> Either<T,U> {
    return .first(value)
  }
  static func buildEither<T: Tuple, U: Tuple>(second value: U) -> Either<T,U> {
    return .second(value)
  }
}

protocol Tuple {
  associatedtype Body: Tuple

  @TupleBuilder var body: Body { get }
}

func make<T>() -> T {
  fatalError()
}

extension Never: Tuple {
  var body: Never {
    return make()
  }
}

struct OneTuple: Tuple {
  var body: Never {
    return make()
  }
}

extension Either: Tuple where T: Tuple, U: Tuple {
  var body: Never {
    return make()
  }
}

struct NTuple<Element: Tuple>: Tuple {
  init(@TupleBuilder _ body: () -> Element) {

  }

  var body: some Tuple {
    return make() as OneTuple
  }
}

enum Kind {
  case first
}

struct Foo: Tuple {
  var constant: Kind

  var body: some Tuple {
    NTuple {
      switch self. {
      case .first:
        OneTuple()
      }
    }
  }
}

Seems like improper references to switch subjects in function builders consistently produce this kind of outcome, which can be somewhat annoying when refactoring SwiftUI code that makes heavy use of enumerations.

@CodaFi
Copy link
Member Author

CodaFi commented Mar 20, 2021

@swift-ci create

@CodaFi
Copy link
Member Author

CodaFi commented Mar 20, 2021

You get nothing but the fallback diagnostic if an invalid member name is typed instead of just a hanging qualified reference.

      switch self.con {

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant