Files
swift-mirror/test/SourceKit/CursorInfo/cursor_ambiguous.swift
Alex Hoppen ef3e1c1d4f [SourceKit] Allow generation of cursor info for declarations from solutions that haven’t aren’t applied to the AST ye
This has two benefits:
1. We can now report ambiguous variable types
2. We are more robust in the generation of results for declarations inside closures. If the closure has an error, we won’t apply the solution to the AST and thus any cursor info that tried to get types out of the AST would fail.

rdar://123845208
2024-03-20 14:52:39 +01:00

49 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
func testAmbiguousFunctionReference() {
func foo(a: Int) {}
func foo(a: String) {}
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):7 %s -- %s | %FileCheck %s --check-prefix LOCAL_FUNC
_ = foo
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):7 %s -- %s | %FileCheck %s --check-prefix LOCAL_FUNC
_ = foo(a: UInt(1))
// LOCAL_FUNC: source.lang.swift.ref.function.free
// LOCAL_FUNC: <Declaration>func foo(a: <Type usr="s:Si">Int</Type>)</Declaration>
// LOCAL_FUNC: SECONDARY SYMBOLS BEGIN
// LOCAL_FUNC: source.lang.swift.ref.function.free
// LOCAL_FUNC: <Declaration>func foo(a: <Type usr="s:SS">String</Type>)</Declaration>
// LOCAL_FUNC: SECONDARY SYMBOLS END
}
func testAmbiguousFunctionResult() {
func foo() -> Int {}
func foo() -> String {}
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):7 %s -- %s | %FileCheck %s --check-prefix AMBIGUOUS_FUNC_RESULT
let value = foo()
// AMBIGUOUS_FUNC_RESULT: source.lang.swift.ref.var.local
// AMBIGUOUS_FUNC_RESULT: <Declaration>let value: <Type usr="s:Si">Int</Type></Declaration>
// AMBIGUOUS_FUNC_RESULT: SECONDARY SYMBOLS BEGIN
// AMBIGUOUS_FUNC_RESULT: source.lang.swift.ref.var.local
// AMBIGUOUS_FUNC_RESULT: <Declaration>let value: <Type usr="s:SS">String</Type></Declaration>
// AMBIGUOUS_FUNC_RESULT: SECONDARY SYMBOLS END
}
struct TestDeduplicateResults {
// The constraints system produces multiple solutions here for the argument type but
// all reference the same declaration. Check that we de-duplicate them and that we
// dont report any secondary sybmols.
static func staticFunc(_ duration: Int) {}
func test() {
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):10 %s -- %s | %FileCheck %s --check-prefix STATIC_FUNC
Self.staticFunc(1 * 1e9)
}
// STATIC_FUNC: source.lang.swift.ref.function.method.static
// STATIC_FUNC: <Declaration>static func staticFunc(_ duration: <Type usr="s:Si">Int</Type>)</Declaration>
// STATIC_FUNC: SECONDARY SYMBOLS BEGIN
// STATIC_FUNC-NEXT: SECONDARY SYMBOLS END
}