-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Xcode 11.4 beta triggers false positive for implicit_getter rule #3074
Comments
May be related, but extension Foo {
@IBInspectable var bar: Bool {
get { _bar }
set { self._bar = newValue }
}
} |
Swift 5.2 removed Swift 5.1{
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
"key.length" : 145,
"key.offset" : 0,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.bodylength" : 28,
"key.bodyoffset" : 12,
"key.kind" : "source.lang.swift.decl.struct",
"key.length" : 41,
"key.name" : "Foo",
"key.namelength" : 3,
"key.nameoffset" : 7,
"key.offset" : 0,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.private",
"key.attributes" : [
{
"key.attribute" : "source.decl.attribute.private",
"key.length" : 7,
"key.offset" : 17
}
],
"key.kind" : "source.lang.swift.decl.var.instance",
"key.length" : 14,
"key.name" : "_bar",
"key.namelength" : 4,
"key.nameoffset" : 29,
"key.offset" : 25,
"key.setter_accessibility" : "source.lang.swift.accessibility.private",
"key.typename" : "Bool"
}
]
},
{
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.bodylength" : 85,
"key.bodyoffset" : 58,
"key.kind" : "source.lang.swift.decl.extension",
"key.length" : 101,
"key.name" : "Foo",
"key.namelength" : 3,
"key.nameoffset" : 53,
"key.offset" : 43,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.bodylength" : 63,
"key.bodyoffset" : 78,
"key.kind" : "source.lang.swift.decl.var.instance",
"key.length" : 79,
"key.name" : "bar",
"key.namelength" : 3,
"key.nameoffset" : 67,
"key.offset" : 63,
"key.setter_accessibility" : "source.lang.swift.accessibility.internal",
"key.typename" : "Bool"
}
]
}
]
} Swift 5.2{
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
"key.length" : 145,
"key.offset" : 0,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.bodylength" : 28,
"key.bodyoffset" : 12,
"key.kind" : "source.lang.swift.decl.struct",
"key.length" : 41,
"key.name" : "Foo",
"key.namelength" : 3,
"key.nameoffset" : 7,
"key.offset" : 0,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.private",
"key.attributes" : [
{
"key.attribute" : "source.decl.attribute.private",
"key.length" : 7,
"key.offset" : 17
}
],
"key.kind" : "source.lang.swift.decl.var.instance",
"key.length" : 14,
"key.name" : "_bar",
"key.namelength" : 4,
"key.nameoffset" : 29,
"key.offset" : 25,
"key.setter_accessibility" : "source.lang.swift.accessibility.private",
"key.typename" : "Bool"
}
]
},
{
"key.bodylength" : 85,
"key.bodyoffset" : 58,
"key.kind" : "source.lang.swift.decl.extension",
"key.length" : 101,
"key.name" : "Foo",
"key.namelength" : 3,
"key.nameoffset" : 53,
"key.offset" : 43,
"key.substructure" : [
{
"key.bodylength" : 63,
"key.bodyoffset" : 78,
"key.kind" : "source.lang.swift.decl.var.instance",
"key.length" : 79,
"key.name" : "bar",
"key.namelength" : 3,
"key.nameoffset" : 67,
"key.offset" : 63,
"key.typename" : "Bool"
}
]
}
]
} I recommend filing a bug in https://bugs.swift.org for this. |
@marcelofabri Their removal in this case was actually intentional. SourceKit's open and edit requests are purely syntactic and don't use the type checker for performance reasons, so they don't actually know what accessibility level extensions and their members have without explicit accessibility annotations. They would previously just report them all as 'internal' in such cases. E.g. in the code below 'x' is actually private, but SourceKit would just report it as internal because without semantic info it doesn't know that 'Foo' refers to a private class:
This behavior overloaded If I'm understanding the "implicit_getter" rule correctly, it seems the issue here is that it isn't really looking for the accessibility level at all, but is using the presence of the As a bit of SwiftSyntax plug, using SwiftSyntax rather SourceKit for these kinds of purely-syntactic rules might be a better fit, for example:
|
Thanks for the detailed response @nathawes!
Yes, that's what it's doing - using it to infer if it's a readonly property or not. We use that assumption in a few other rules as well.
That's doable for this rule, but in theory you could have another type declaration inside of a computed property body, so we'd need to handle that case. However, other rules use this to treat
That only works if we provide a buildlog, right? This is how the (experimental) "analyzer" rules work right now, but they're very slow and require a clean build
That's my long term goal, I have a PR adding it to the project (#3054), but there're some tradeoff:
Besides that, SwiftSyntax on Swift 5.1 is still a bit slower than using SourceKit directly. I know that this is much better on the nightly builds already, but we can't rely on them until there's a new stable release. That's why I was planing to use it mainly for opt-in rules until Swift 5.2 is officially released. |
@marcelofabri Yeah, I suspect it's pretty uncommon, but you'd need to ignore any occurrences within the ranges of the
You won't get types for everything without proper arguments (and valid Swift code), but if you just pass the file name as the only compiler argument you'll still get a response for every declaration location, just not references unless they're locally resolvable. For declarations, if a type couldn't be resolved you'll see "<<error type>>" wherever you'd normally get a type name in the response. The trailing comments below are what you get from the
The braces tell you whether it's computed/stored, the get/set tells you whether its settable for computed properties, and the var/let keyword tells you whether its settable for stored properties. It would be one request per declaration unlike the structure data though, so performance probably won't be as good. I think you could get this info from the syntax map / structure data too, but it'd be a bit more complicated.
Oh, nice! That's great to hear.
Yeah, we definitely know this is a pain point. We're hoping we can use SwiftPM's proposed binary dependencies feature in future to drop the requirement that the toolchain has a compatible version of the parser library.
I'm not that familiar with Carthage/Cocoapods, but I assume you mean they need to be in the SwiftSyntax repo? I'm not sure there'd be much objection to adding them if someone's willing to keep an eye on/maintain them.
Yeah that makes sense. I was meaning SwiftSyntax as a more long term solution rather than for this bug specifically. SourceKit's syntactic requests aren't getting too much attention anymore by comparison. |
New Issue Checklist
Describe the bug
Given the following code:
The getter triggers the
implicit_getter
warning in Xcode 11.4 beta.Note that this wasn't an issue on previous versions of Xcode and that it seems to be a bug isolated to extensions.
Environment
The text was updated successfully, but these errors were encountered: