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

[SR-14300] Documentation comment being parsed incorrectly. #522

Closed
swift-ci opened this issue Mar 4, 2021 · 4 comments
Closed

[SR-14300] Documentation comment being parsed incorrectly. #522

swift-ci opened this issue Mar 4, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@swift-ci
Copy link

swift-ci commented Mar 4, 2021

Previous ID SR-14300
Radar None
Original Reporter ccdoky (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Environment

macOS: 11.2.1

xcode: 12.4(12D4e)

swift: Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)

Additional Detail from JIRA
Votes 0
Component/s SourceKit-LSP, SwiftSyntax
Labels Bug
Assignee None
Priority Medium

md5: 584ffe581d5e132234624ebd7b6b4ebe

Issue Description:

If you write a document like: 

/** 
./folder/*
*/ 

Xcode will throw an errorUnterminated '/*' comment
class Test {
    /**
     Run lizard code cyclomatic complexity analysis.


     - parameters:
       - exclude: Exclude files that match this pattern. * matches everything, ? matches any single character, "./folder/*" exclude everything in the folder recursively. Multiple patterns can be specified. Don't forget to add "" around the pattern
     It counts 1)the nloc (lines of code without comments), 2)CCN (cyclomatic complexity number), 3)token count of functions. 4)parameter count of functions.
    */
    public func lizard(sourceFolder: String? = nil,
                       language: String = "swift",
                       exportType: String? = nil,
                       ccn: Any? = nil,
                       length: Any? = nil,
                       executable: String? = nil) {
    }
}
@typesanitizer
Copy link

Swift allows /* */ to nest. What is happening here is that the /* in ./folder/* is getting matched up with the */ leading to the first comment being unclosed. You can replace the ./folder/* with ./folder/\ * (without the space between the backslash and the *, but I can't get JIRA to work properly), I think that should do the trick.

@swift-ci
Copy link
Author

swift-ci commented Mar 5, 2021

Comment by phil zhang (JIRA)

theindigamer (JIRA User)

First of all thank you for your reply.
However, I do not agree with you.
If it is a grammatical problem, it can be solved as you said.

However, the problem here is the annotation document, and the annotation document is universal and has nothing to do with language.
This way of writing is normal in other languages. So, I think this is a bug in swift.

For example, putting this comment in other languages can be parsed normally.

js:

oc:

@typesanitizer
Copy link

Both Javascript and C (and hence ObjC) do not allow nesting block comments. Here is a JS fiddle screenshot.

Compare that to Swift (screenshot from Compiler Explorer)

Rust which allows nested block comments, also behaves similar to Swift. (See https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=75c9dc60c88a9fca0ceaf65cba5841b7 )

@swift-ci
Copy link
Author

swift-ci commented Mar 5, 2021

Comment by phil zhang (JIRA)

Haha, I see. Thank you very much.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants