Skip to content

Commit 6e4f711

Browse files
authored
Merge pull request #79512 from DougGregor/unsafe-storage-checking-generic
Fix declaration context for unsafe storage checking
2 parents 052958e + c308cfd commit 6e4f711

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/TypeCheckUnsafe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void swift::checkUnsafeStorage(NominalTypeDecl *nominal) {
443443

444444
// Look for any unsafe storage in this nominal type.
445445
SmallVector<UnsafeUse, 4> unsafeUses;
446-
UnsafeStorageVisitor(ctx, unsafeUses).visit(nominal, nominal->getDeclContext());
446+
UnsafeStorageVisitor(ctx, unsafeUses).visit(nominal, nominal);
447447

448448
// If we didn't find any unsafe storage, there's nothing to do.
449449
if (unsafeUses.empty())

test/Unsafe/unsafe.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,11 @@ class ClassWithUnsafeStorage {
191191
var int: Int = 0
192192
var array: [UnsafeSuper]? = nil // expected-note{{property 'array' involves unsafe type 'UnsafeSuper'}}
193193
}
194+
195+
// expected-warning@+3{{generic struct 'GenericStructWithUnsafeThings' has storage involving unsafe types}}
196+
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}
197+
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}
198+
struct GenericStructWithUnsafeThings<T> {
199+
var property: T
200+
var pointer: PointerType // expected-note{{property 'pointer' involves unsafe type 'PointerType'}}
201+
}

0 commit comments

Comments
 (0)