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
[CodeCompletion] Fix an issue that causes an iterator to be invalidated while iterating
In `SourceLookupCache::lookupVisibleDecls`, copy the top level values before iterating them.
If we have 'addinitstotoplevel' enabled, calling 'addConstructorCallsForType' can cause macros to get expanded, which can then cause new members ot get added to 'TopLevelValues', invalidating the current iterator.
I have not been able to reduce this to a test case that doesn’t rely on the `Observation` module in the SDK but here is the test case with which I was able to reproduce the issue very reliably.
```swift
import Foundation
import Observation
@observable class MyObject {}
extension MyObject {}
// RUN: ~/sbin/sourcekitd-test \
// RUN: -req=complete.open \
// RUN: -req-opts=addinitstotoplevel=1 \
// RUN: -pos=8:1 \
// RUN: %s \
// RUN: -- \
// RUN: %s \
// RUN: -Xfrontend \
// RUN: -load-plugin-library \
// RUN: -Xfrontend \
// RUN: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/libObservationMacros.dylib \
// RUN: -sdk \
// RUN: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk
```
rdar://109202157
0 commit comments