You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Block tests/suites in extensions to syntactic sugar types ([T], [T:U], T?) (#361)
This PR blocks tests and suites in extensions to types declared using
syntactic sugar. For example, the following is invalid:
```swift
extension [Int] {
@test func f() {}
}
```
I doubt this is going to be a common pattern, but it's just as invalid
as saying `extension Array<Int>` for the same reasons: if it
successfully compiles, it produces metadata for a test that we cannot
instantiate at runtime (because the type we can see in the metadata is
still generic, not specialized.)
There is a guard symbol emitted by our macro already that triggers a
diagnostic if a test or suite is in a generic type, but `extension [T]`
is fully specialized and does not trigger the diagnostic, so it's
important that we catch this issue and make sure some diagnostic is
emitted.
With this change, when using swift-syntax-600, you should now see:
```swift
extension [Int] {
@test func f() {} // 🛑 Attribute 'Test' cannot be applied to a function
// within a generic extension to type '[Int]'
}
```
This PR also introduces an environment variable you can set when running
`swift test` to opt into a different swift-syntax version, which makes
testing with swift-syntax-600 easier. This diagnostic will be removed as
redundant if/when #338 is merged.
Finally, this PR fixes some unrelated unit tests that fail when using
swift-syntax-600.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
message:"Attribute \(_macroName(attribute)) cannot be applied to \(_kindString(for: decl, includeA:true)) within function '\(functionName)'",
358
+
syntax:syntax,
359
+
message:"Attribute \(_macroName(attribute)) cannot be applied to \(_kindString(for: decl, includeA:true)) within\(generic) function '\(functionName)'",
message:"Attribute \(_macroName(attribute)) cannot be applied to \(_kindString(for: decl, includeA:true)) within \(nodeKind) '\(declGroupName)'",
352
387
severity:.error
353
388
)
354
389
}else{
390
+
letnodeKind=if genericClause !=nil{
391
+
"a generic \(_kindString(for: node))"
392
+
}else{
393
+
_kindString(for: node, includeA:true)
394
+
}
355
395
returnSelf(
356
-
syntax:Syntax(attribute),
357
-
message:"Attribute \(_macroName(attribute)) cannot be applied to \(_kindString(for: decl, includeA:true)) within \(_kindString(for: node, includeA:true))",
396
+
syntax:syntax,
397
+
message:"Attribute \(_macroName(attribute)) cannot be applied to \(_kindString(for: decl, includeA:true)) within \(nodeKind)",
0 commit comments