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

CharacterSet Parser throws EXC_BREAKPOINT #333

Open
pacu opened this issue Dec 15, 2023 · 0 comments
Open

CharacterSet Parser throws EXC_BREAKPOINT #333

pacu opened this issue Dec 15, 2023 · 0 comments

Comments

@pacu
Copy link

pacu commented Dec 15, 2023

When using a CharacterSet inside a parser, any character that is not in the set will crash the process.

Version:

 {
      "identity" : "swift-parsing",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/pointfreeco/swift-parsing",
      "state" : {
        "revision" : "a0e7d73f462c1c38c59dc40a3969ac40cea42950",
        "version" : "0.13.0"
      }
    }

Proof of Concept:

Run the following test:

extension CharacterSet {
    static let naiveSet = CharacterSet(charactersIn: "abc")
}

let naiveParser = Parse {
    CharacterSet.naiveSet
}

final class LameTest: XCTestCase {
    func testNaiveSetWorks() {
        let validInput = "abacabb"[...]
        let result = naiveParser.parse(validInput)
        XCTAssertEqual(result, validInput)

        let invalidInput = "abacad"[...]
        
        let unresult = naiveParser.parse(invalidInput)
        XCTAssertEqual(unresult, invalidInput)
    }
}

Expected

The parse() should throw and compiler must err if not called with a try statement, and then actually throw an error.

Result

The function crashes. The compiler does not let parse() be called with a try since it considers it "not throwing"

image

Workaround:

let naiveParser = Parse {
    CharacterSet.naiveSet.eraseToAnyParser()
}
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

1 participant