Files
swift-mirror/test/IDE/complete_rdar75200217.swift
Alex Hoppen 7e2898c4e4 [CodeComplete] Fix cyclic dependency error during code completion
In the added test case, we were hitting a cyclic dependency error in the request evaluator during code completion, that’s caued as follows:
– To complete at `#^COMPLETE^#`, we need to get the `NamingPattern` of `start`.
– Retrieving the `NamingPattern` of `start` causes the entire `if`-condition to be type checked, including `end`
– Type checking `end` requires getting the `NamingPattern` of `start`
=> Cyclic dependency

To resolve the issue, I added a special case to `NamingPatternRequest` that only type-checks the `StmtConditionElement` that actually defines the `VarDecl`.

Fixes rdar://75200217
2021-03-25 22:13:52 +01:00

36 lines
1.2 KiB
Swift

// RUN: %target-swift-ide-test -code-completion -source-filename %s -F %S/Inputs/mock-sdk -code-completion-token=COMPLETE | %FileCheck %s
enum Encoding {
case utf8
}
func foo(bytes: ArraySlice<UInt16>, encoding: Encoding) {
fatalError()
}
extension Array {
func bar<R>(r: R) -> ArraySlice<Element> where R : RangeExpression, Int == R.Bound {
fatalError()
}
}
/// The issue, that caused this to fail was that type checking `start` caused
/// the entire `if` condition to be type-checked, thus also type-checking `end`
/// which depends on `start`, thus creating a dependency cycle in the request
/// evaluator.
/// Thus `end` would get assigned an error type, causing `a` to be an error
/// type and thus the completion on `encoding` fails.
/// We need a particular order of type check requests to hit this behaviour,
/// that's why the test case feels over-complicated.
func deserializeName(_ data: Array<UInt16>, flag: Bool) {
if flag, let start = Optional(Array<UInt16>.Index()), let end = Optional(start) {
let range = start..<end
let a = data.bar(r: range)
foo(bytes: a, encoding: .#^COMPLETE^#)
}
}
// CHECK: Begin completions
// CHECK-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Identical]: utf8[#Encoding#];
// CHECK: End completions