Skip to content

Commit 3b388df

Browse files
committed
SILGen: Don't try using materializeForSet with storage in an @objc protocol
Fixes <https://bugs.swift.org/browse/SR-2669>.
1 parent 5f9fe6f commit 3b388df

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,11 @@ namespace {
831831
return true;
832832
}
833833

834-
// If the declaration is dynamically dispatched through a protocol,
835-
// we have to use materializeForSet.
836-
if (isa<ProtocolDecl>(decl->getDeclContext()))
837-
return true;
834+
// If the declaration is dynamically dispatched through a
835+
// non-ObjC protocol, we have to use materializeForSet.
836+
if (auto *protoDecl = dyn_cast<ProtocolDecl>(decl->getDeclContext()))
837+
if (!protoDecl->isObjC())
838+
return true;
838839

839840
return false;
840841
}

test/SILGen/objc_protocols.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,12 @@ extension InitializableConformerByExtension: Initializable {
280280
}
281281
}
282282
// CHECK-LABEL: sil hidden [thunk] @_TToFC14objc_protocols33InitializableConformerByExtensionc
283+
284+
// Make sure we're crashing from trying to use materializeForSet here.
285+
@objc protocol SelectionItem {
286+
var time: Double { get set }
287+
}
288+
289+
func incrementTime(contents: SelectionItem) {
290+
contents.time += 1.0
291+
}

0 commit comments

Comments
 (0)