Skip to content

Commit 1cbeee6

Browse files
committed
Fix Fix-It location for "unsafe" when calling an initializer
The implicit reference to the initializer was tripping up the logic for finding the appropriate place to insert "unsafe", and it was ending up in the middle of the expression.
1 parent 73c875d commit 1cbeee6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
31723172
return false;
31733173

31743174
return isa<AbstractClosureExpr>(e) || isa<DiscardAssignmentExpr>(e) ||
3175-
isa<AssignExpr>(e) || (isa<DeclRefExpr>(e) && e->isImplicit());
3175+
isa<AssignExpr>(e);
31763176
}
31773177

31783178
static bool isAnchorTooEarly(Expr *e) {

test/Unsafe/unsafe.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ class ExclusivityChecking {
123123
// TODO: diagnose the need for @unsafe when there's an unsafe superclass.
124124
class UnsafeSub: UnsafeSuper { }
125125

126+
// -----------------------------------------------------------------------
127+
// Miscellaneous expression issues
128+
// -----------------------------------------------------------------------
129+
130+
struct BufferThingy<T> {
131+
@unsafe init(count: Int) { }
132+
}
133+
134+
func testConstruction() {
135+
let _ = BufferThingy<Int>(count: 17) // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{11-11=unsafe }}
136+
// expected-note@-1{{reference to unsafe initializer 'init(count:)'}}
137+
}
138+
126139
// -----------------------------------------------------------------------
127140
// Declaration references
128141
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)