File: complete_call_pattern.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (92 lines) | stat: -rw-r--r-- 3,359 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// RUN: %batch-code-completion -disable-objc-attr-requires-foundation-module

struct FooStruct {
  init() {}
  init(a: Int) {}
  init(a: Int, b: Float) {}
  mutating func instanceFunc2(_ a: Int, b: inout Double) {}
}

func testInsideFunctionCall_1(_ x: inout FooStruct) {
  x.instanceFunc(#^BEFORE_COMMA^#,
// BEFORE_COMMA-NOT: Pattern/{{.*}}:{{.*}}({{.*}}{#Int#}
// BEFORE_COMMA-NOT: Decl[InstanceMethod]/{{.*}}:{{.*}}({{.*}}{#Int#}
}
func testInsideFunctionCall_2(_ x: inout FooStruct) {
  x.instanceFunc(#^BEFORE_PLACEHOLDER^#<#placeholder#>
// BEFORE_PLACEHOLDER-NOT: Pattern/{{.*}}:{{.*}}({{.*}}{#Int#}
// BEFORE_PLACEHOLDER-NOT: Decl[InstanceMethod]/{{.*}}:{{.*}}({{.*}}{#Int#}
}
func testConstructor() {
  FooStruct(#^CONSTRUCTOR^#,
// CONSTRUCTOR: Begin completions, 3 items
// CONSTRUCTOR-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['('][')'][#FooStruct#];
// CONSTRUCTOR-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#a: Int#}[')'][#FooStruct#];
// CONSTRUCTOR-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#a: Int#}, {#b: Float#}[')'][#FooStruct#];
}

func firstArg(arg1 arg1: Int, arg2: Int) {}
func testArg2Name3() {
  firstArg(#^LABELED_FIRSTARG^#,
// LABELED_FIRSTARG: Begin completions, 1 item
// LABELED_FIRSTARG-DAG: Decl[FreeFunction]/CurrModule/Flair[ArgLabels]: ['(']{#arg1: Int#}, {#arg2: Int#}[')'][#Void#];
}

func optionalClosure(optClosure: ((Int) -> Void)?, someArg: Int) {
  optClosure?(#^OPTIONAL_CLOSURE^#someArg)
  // OPTIONAL_CLOSURE-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: someArg[#Int#]; name=someArg
}

func optionalProtocolMethod() {
  @objc protocol Foo {
    @objc optional func foo(arg: Int)
  }

  func test(foo: Foo) {
    foo.foo?(#^OPTIONAL_PROTOCOL_METHOD^#)
    // OPTIONAL_PROTOCOL_METHOD-DAG: Decl[InstanceMethod]/CurrNominal/Flair[ArgLabels]: ['(']{#arg: Int#}[')'][#Void#];
  }
}

func subscriptAccess(info: [String: Int]) {
  info[#^SUBSCRIPT_ACCESS^#]
// SUBSCRIPT_ACCESS: Pattern/CurrNominal/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<[String : Int], Value>#}[']'][#Value#];
}

struct StaticMethods {
  static func before() {
      self.after(num)#^AFTER_STATIC_FUNC^#
  }
  static func after(_ num: Int) -> (() -> Int) {}
// AFTER_STATIC_FUNC: Begin completions, 2 items
// AFTER_STATIC_FUNC-DAG: Keyword[self]/CurrNominal:          .self[#() -> Int#];
// AFTER_STATIC_FUNC-DAG: Pattern/CurrModule/Flair[ArgLabels]: ()[#Int#];
// AFTER_STATIC_FUNC: End completions
}

struct AmbiguousInResultBuilder {
  @resultBuilder
  struct MyViewBuilder {
    static func buildBlock(_ elt: Text) -> Int {
      53
    }
  }

  struct Text {
    init(verbatim content: String) {}
    init<S>(_ content: S) where S : StringProtocol {}
  }

  func foo(@MyViewBuilder content: () -> Int) {}

  func test(myStr: String) {
    foo {
      Text(#^AMBIGUOUS_IN_RESULT_BUILDER?xfail=TODO^#)
// AMBIGUOUS_IN_RESULT_BUILDER: Begin completions
// AMBIGUOUS_IN_RESULT_BUILDER-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#verbatim: String#}[')'][#Text#]; name=verbatim:
// AMBIGUOUS_IN_RESULT_BUILDER-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#(content): _#}[')'][#Text#]; name=:
// AMBIGUOUS_IN_RESULT_BUILDER-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: myStr[#String#]; name=myStr
// AMBIGUOUS_IN_RESULT_BUILDER: End completions
    }
  }
}