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

tests fail to build with Xcode 15.3 #342

Open
dave256 opened this issue Mar 25, 2024 · 2 comments
Open

tests fail to build with Xcode 15.3 #342

dave256 opened this issue Mar 25, 2024 · 2 comments

Comments

@dave256
Copy link

dave256 commented Mar 25, 2024

I assume these tests built before but with Xcode 15.3, the Swift compiler fails with compiler issues:

swift-parsing/Sources/swift-parsing-benchmark/JSON.swift:71:84 Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)

swift-parsing/Tests/ParsingTests/OneOfTests.swift:272:86 Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)

I did not file a bug at swift.org as I didn't feel I could narrow it down.

@cham-s
Copy link

cham-s commented Apr 1, 2024

I'm not sure why but in this version of XCode the compiler is not able to infer the type compare to the previous versions.
A possible fix is to provide more type information to help the compiler.
But it makes the code more verbose.

For instance in

We can add more type information on the JSONObject Parser:

//Before
struct JSONObject: ParserPrinter {
  var body: some ParserPrinter<Substring.UTF8View, [String: JSONValue.Output]> {
    "{".utf8
    Many(into: [String: JSONValue.Output]()) { object, pair in
      let (name, value) = pair
      object[name] = value
    } decumulator: { object in
      (object.sorted(by: { $0.key < $1.key }) as [(String, JSONValue.Output)])
        .reversed()
        .makeIterator()
    } element: {
      Whitespace()
      JSONString()
      Whitespace()
      ":".utf8
      JSONValue()
    } separator: {
      ",".utf8
    } terminator: {
      "}".utf8
    }
  }
}

// After
struct JSONObject: ParserPrinter {
  var body: some ParserPrinter<Substring.UTF8View, [String: JSONValue.Output]> {
    "{".utf8
    Many(into: [String: JSONValue.Output]()) { (
      object: inout [String: JSONValue.Output],
      pair: (String, JSONValue.Output)
    ) in
      let (name, value) = pair
      object[name] = value
    } decumulator: { object in
      (object.sorted(by: { $0.key < $1.key }) as [(String, JSONValue.Output)])
        .reversed()
        .makeIterator()
    } element: {
      Whitespace()
      JSONString()
      Whitespace()
      ":".utf8
      JSONValue()
    } separator: {
      ",".utf8
    } terminator: {
      "}".utf8
    }
  }
}

I have submitted a pull request for this.

@dave256
Copy link
Author

dave256 commented Apr 4, 2024

Thanks. I wondered it was an issue with the compiler not being able to infer types. I used to see that error years ago with Swift but haven't seen it recently. @cham-s thanks for submitting a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants