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

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

Open
chrishulton opened this issue Jan 9, 2018 · 3 comments
Open

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

chrishulton opened this issue Jan 9, 2018 · 3 comments

Comments

@chrishulton
Copy link

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

  • OS Info: macOS Version 10.13.2 (Build 17C88)
  • Yanagiba/swift-ast version: 0.4.1

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link

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.

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

No branches or pull requests

3 participants