yanagiba / swift-ast

A Swift AST parser and visitor that is written in Swift.
Apache License 2.0
354 stars 40 forks source link

Parser crashes when using value matching in catch clause #69

Closed TheDutchDevil closed 6 years ago

TheDutchDevil commented 6 years ago

🚨New Issue Checklist🚨

Issue Summary

The file attached to this issue can be successfully built and executed using swiftc with no additional parameters.

Environment

Reproduction Steps

Parse the included file using swift-ast -dump-ast <file> and observe that it fails to parse the value matching in the catch clause.

Sample code ``` enum VendingMachineError: Error { case insufficientFunds(coinsNeeded: Int) } func throwsSomething() throws -> String { return "This doesn't matter" } do { try throwsSomething() } catch VendingMachineError.insufficientFunds(3) { print("3 coins missing") } catch VendingMachineError.insufficientFunds(let coinsNeeded) { print("Not 3 coins missing") } catch { print("No coins missing") } ``` Command to run `swift-ast` with the code above: `swift-ast /home/nathan/value_ex.swift`

Expected Result

A valid ast dump for the test file, it appears that swift-ast does not correctly parse the type instantiation for the value matching.

Actual Behavior

/home/nathan/value_ex.swift:17:45 fatal: expectedPattern
ryuichis commented 6 years ago

@TheDutchDevil thanks for letting me know. I can reproduce the issue locally. I will try my best to work on a fix between Christmas and New Year, otherwise, will be early Jan.

TheDutchDevil commented 6 years ago

@ryuichis Thanks a lot for your quick response and work on the parser!

TheDutchDevil commented 6 years ago

Thanks a lot for the quick fix!

ryuichis commented 6 years ago

@TheDutchDevil no problem, thanks for informing me with the issue. Happy new year!