Merge pull request #79512 from DougGregor/unsafe-storage-checking-generic

Fix declaration context for unsafe storage checking
This commit is contained in:
Doug Gregor
2025-02-20 02:21:30 -10:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -443,7 +443,7 @@ void swift::checkUnsafeStorage(NominalTypeDecl *nominal) {
// Look for any unsafe storage in this nominal type.
SmallVector<UnsafeUse, 4> unsafeUses;
UnsafeStorageVisitor(ctx, unsafeUses).visit(nominal, nominal->getDeclContext());
UnsafeStorageVisitor(ctx, unsafeUses).visit(nominal, nominal);
// If we didn't find any unsafe storage, there's nothing to do.
if (unsafeUses.empty())

View File

@@ -191,3 +191,11 @@ class ClassWithUnsafeStorage {
var int: Int = 0
var array: [UnsafeSuper]? = nil // expected-note{{property 'array' involves unsafe type 'UnsafeSuper'}}
}
// expected-warning@+3{{generic struct 'GenericStructWithUnsafeThings' has storage involving unsafe types}}
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}
struct GenericStructWithUnsafeThings<T> {
var property: T
var pointer: PointerType // expected-note{{property 'pointer' involves unsafe type 'PointerType'}}
}