File: cursor_ambiguous.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (48 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
  // don’t 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
}