Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Strange results with extensions and types in same file. #34

Closed
crayment opened this issue Apr 1, 2020 · 3 comments · Fixed by #53
Closed

Strange results with extensions and types in same file. #34

crayment opened this issue Apr 1, 2020 · 3 comments · Fixed by #53
Labels
bug Something isn't working
Milestone

Comments

@crayment
Copy link

crayment commented Apr 1, 2020

Thanks this looks awesome! I did a quick test and I think I found some bugs.

I created a new Swift package and put the following in the source file:

/// Says hello
public func sayHello() {
    print("Hello!")
}

public extension NSNumber {
    /// Does this number represent a Bool
    public var isBool: Bool { return CFBooleanGetTypeID() == CFGetTypeID(self) }
}

public extension Result where Failure == Error {
    /// Converts a throwing block into a Result
    /// If any error is thrown a failure result is returned with the error. Otherwise success with the blocks return value.
    public static func of(_ block: () throws -> Success) -> Result<Success, Error> {
        do {
            return try .success(block())
        } catch {
            return .failure(error)
        }
    }
}

/**
 The default generated struct!
 */
struct spm_test {
    var text = "Hello, World!"
}

When I run the generator via swift doc generate Sources --module-name spm-test I get the following:

Home.md

# Types

  - [NSNumber.Result.spm\_test](NSNumber_Result_spm_test)

# Operators

  - [sayHello()](sayHello\(\))

NSNumber_Result_spm_test.md

# NSNumber.Result.spm\_test

The default generated struct\!

``` swift
struct spm_test
```

## Properties

## text

``` swift
var text = "Hello, World!"
```

sayHello().md

# sayHello()

## sayHello()

Says hello

``` swift
public func sayHello()
```

I think there are three bugs here:

  1. Notice how the spm_test struct is nested under the NSNumber and Result types.
  2. I don't get any docs for the public extensions.
  3. The top level sayHello function is documented as an operator.
@mattt
Copy link
Contributor

mattt commented Apr 1, 2020

Thanks for taking a look and filing these bugs, @crayment. It looks like this is another incarnation of #16, or perhaps another similar bug in how I'm capturing declarations through SwiftSyntax. I'll take a look at resolving this with our current approach (I suspect it'll be a small change). Looking forward, #31 will most likely be the fix, long-term.

@mattt
Copy link
Contributor

mattt commented Apr 1, 2020

@crayment To help me reproduce this locally, can you please share the output of swift --version on your machine?

@crayment
Copy link
Author

crayment commented Apr 1, 2020

You bet!

swift --version:

Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0

Thanks again!

@mattt mattt added the bug Something isn't working label Apr 2, 2020
@mattt mattt closed this as completed in #53 Apr 5, 2020
@mattt mattt added this to the 1.0.0-beta.2 milestone Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants