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

Inline-assigned property has no displayed type #138

Closed
a2 opened this issue Jul 2, 2020 · 4 comments · Fixed by #150
Closed

Inline-assigned property has no displayed type #138

a2 opened this issue Jul 2, 2020 · 4 comments · Fixed by #150
Milestone

Comments

@a2
Copy link

a2 commented Jul 2, 2020

image

The following renders as above without the Bool type displayed:

var allowsEncodingAsPlainString = true
@mattt
Copy link
Contributor

mattt commented Jul 14, 2020

@a2 This is a limitation of using a syntactic parse (see #31). Without more information, it's impossible to know whether allowsEncodingAsPlainString is Bool or some other type that conforms to ExpressibleByBooleanLiteral.

For declarations with an implicit type like this, would showing the default value be acceptable in your opinion? (e.g. var allowsEncodingAsPlainString = true) What if there was something in the UI (like a ?⃝) with an explanation of what's going on?

@mattt
Copy link
Contributor

mattt commented Jul 31, 2020

This is a regression caused by 93b33c1#diff-4082294eb6d0c0415becf026802c8cfcR188. To fix the immediate problem, I have a patch in #150 that only omits initializer clause if its a closure or function call expression. conventional literal expressions (boolean, integer, floating-point, string, array, dictionary, etc.) will now be shown.

After

Screen Shot 2020-07-31 at 06 44 50

mattt added a commit that referenced this issue Jul 31, 2020
…able declaration code blocks (#150)

* Omit initializer expression if closure or function call to ensure reasonable declaration code blocks.

Resolves #138

* Add changelog entry for #150
@coybit
Copy link

coybit commented Dec 7, 2020

I ran into a problem that seems to be a special case of this issue. For this piece of code:

public struct Vendor {
    var name: String
    var address: String
    
    fileprivate static var main1: Vendor {
        Vendor(name: "test", address: "test")
    }
    
    fileprivate static func main2() -> Vendor {
        Vendor(name: "test", address: "test")
    }
}

fileprivate let main3 = Vendor(name: "test", address: "test")
fileprivate func main4() -> Vendor {
    Vendor(name: "test", address: "test")
}

public class Device {
    public var vendor1: Vendor = Vendor.main1
    public var vendor2: Vendor = Vendor.main2()
    public var vendor3: Vendor = main3
    public var vendor4: Vendor = main4()
}

The following document is generated:
localhost_8000_Device_

swift doc --version
1.0.0-beta.5

As you see the initial values of vendor1 and vendor3 are exposed.

@coybit
Copy link

coybit commented Dec 7, 2020

I manged to ommit the initializer clause from the generated document by adding MemberAccessExprSyntax (for vendor1) and IdentifierExprSyntax (for vendor3) (SwiftSyntax+Extensions.swift file):

if let value = binding.initializer?.value,
   value.is(ClosureExprSyntax.self) || value.is(FunctionCallExprSyntax.self) || value.is(MemberAccessExprSyntax.self) || value.is(IdentifierExprSyntax.self)
{
    return binding.withInitializer(nil)
                  .withAccessor(nil)
} else {
    return binding.withAccessor(nil)
}

Screenshot 2020-12-07 at 17 29 25

I don't know what side-effect this change may have. I'm looking into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants