yanagiba / swift-ast

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

Parse failure on func(arg:)) syntax #79

Open chrishulton opened 6 years ago

chrishulton commented 6 years ago

Issue Summary

The parser fails with expected expression for syntax like the following:

return uti.flatMap(mimeType(uti:))

I included a sample of code from kickstarter/ios-oss, and have a few additional examples included below.

The sample code does seem to run successfully with swift 4.

Environment

Reproduction Steps

Sample code ``` import Foundation private func mimeType(extension: String, where: CFString? = nil) -> String? { let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, `extension` as CFString, `where`)?.takeRetainedValue() return uti.flatMap(mimeType(uti:)) } private func mimeType(uti: CFString) -> String? { return UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() as String? } ``` Command to run `swift-ast` with the code above: `swift-ast /Users/chrishulton/code/testing/swift_qa/failing_cases/expected_expression.swift`

Expected Result

The code should be able to be parsed.

Actual Behavior

There is a fatal error: expected expression

/Users/chrishulton/code/testing/swift_qa/failing_cases/expected_expression.swift:7:35 fatal: expectedExpr

Even Better

Here are a few additional failing files for this case:

Let me know if I can provide any more information! Thanks!

ryuichis commented 6 years ago

If this is something obvious, please pardon me for my ignorance, but I don't see this syntax defined in swift language reference, nor I personally wrote this kind of code in the past. Could you explain me how to interpret this return uti.flatMap(mimeType(uti:))? especially what uti does in this case? Is it the argument name? Then what's the value for that parameter? Somehow it got inferred based on context or this is the value? I am confused here.

ryuichis commented 6 years ago

Ah, I think I know what's going on here... flatMap can take a function type as its value, and mineType(uti:) is the signature of the reference function...

Thanks for informing me this case. I will try to work on a fix soon.

ryuichi-assistant commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment.