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

Infinite loop is occurring in MockingBird shell script during unit test build phases #300

Open
Caleb-Bolton opened this issue May 11, 2022 · 7 comments

Comments

@Caleb-Bolton
Copy link

Caleb-Bolton commented May 11, 2022

When building my unit tests, the MockingBird build phase shell script spams the logs seemingly infinitely (or at least until Xcode seizes up) with the following warning:

Ignoring unknown parameter attribute '@convention(block)' in function type declaration 'execute work: @escaping @convention(block) () -> Void'

which looks like it's coming from this line:
https://github.com/birdrides/mockingbird/blob/2108f83899745b0e08851caed10a4917757404b3/Sources/MockingbirdGenerator/Parser/Models/Function.swift#L99

Here is a picture of the logs, notice the 65535 count of warnings in the top right:
image

@Caleb-Bolton
Copy link
Author

Caleb-Bolton commented May 11, 2022

Looks like the parser fails to move forward from the '@' character in '@convention(block)' as once it encounters an unrecognized '@' attribute, it looks for the next non-letter, non-number character... which is the '@' character we're already on, so it infinitely loops.

It obviously needs to move past this attribute, I'm not familiar with this code though so I don't know what this would look like.

          var mutableComponent = component
          while (true) { // TODO: Use SwiftSyntax to properly parse this...
            if mutableComponent.starts(with: "@escaping") {
              attributes.insert(.escaping)
              mutableComponent = mutableComponent.dropFirst("@escaping".count)
            } else if mutableComponent.starts(with: "@autoclosure") {
              attributes.insert(.autoclosure)
              mutableComponent = mutableComponent.dropFirst("@autoclosure".count)
            } else if mutableComponent.hasPrefix("@") { // Unknown parameter attribute.
              logWarning("Ignoring unknown parameter attribute \(String(mutableComponent).singleQuoted) in function type declaration \(String(serialized).singleQuoted)")
              let index = mutableComponent.firstIndex(where: { !$0.isLetter && !$0.isNumber })
                ?? mutableComponent.endIndex
              mutableComponent = mutableComponent[index...]
            } else if mutableComponent == "inout" {
              attributes.insert(.inout)
              mutableComponent = mutableComponent.dropFirst("inout".count)
            } else if mutableComponent == "..." {
              attributes.insert(.variadic)
              mutableComponent = mutableComponent.dropFirst("...".count)
            } else {
              break
            }
          }

fabianmuecke pushed a commit to fabianmuecke/mockingbird that referenced this issue Jul 15, 2022
fabianmuecke pushed a commit to fabianmuecke/mockingbird that referenced this issue Jul 15, 2022
@amine2233
Copy link

have the same failure, do you have any update for it ?

@AlexanderMarchant
Copy link

Same problem here.

It can be easily reproduced by creating a protocol for the DispatchQueue method(s).

protocol DispatchQueueProtocol
{
    func async(group: DispatchGroup?, qos: DispatchQoS, flags: DispatchWorkItemFlags, execute work: @escaping @convention(block) () -> Void)
}

extension DispatchQueue: DispatchQueueProtocol {}

I think it should also be noted, this problem freezes and crashes Xcode for me when I try to run my unit tests target.

@Narayane
Copy link

Narayane commented Sep 27, 2023

Hi,
Any updates or workarounds? cc @andrewchang-bird
@fabianmuecke possible to make a PR with your fix on mockingbird repo?
Thanks

@fabianmuecke
Copy link

Sorry, @Narayane, I don't even remember what I did there and why it fixed the issue. 😬 My new employer doesn't use Mockingbird, so I doubt I'll find time to update my fork and make a PR anytime soon.

Please, feel free to make a PR with the change yourself, though. Looks like the fix itself seemed to be just adding dropFirst(). 🤔

@Narayane
Copy link

Narayane commented Oct 9, 2023

Hi,

I tried to exclude relative file but without success FYI ⬆️

@stidch
Copy link

stidch commented Feb 2, 2024

Looks related to #310

Has anybody found a working workaround?

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

6 participants