Skip to content

[5.1][SourceKit] Extend opaque type results test case #25557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions test/SourceKit/CursorInfo/cursor_some_type.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
public protocol Proto {
associatedtype Assoc
func method() -> Assoc
}

public class Base {}

public protocol Proto {}
public class Derived: Base, Proto {
public func method() -> Int {}
}

public func foo() -> some Base & Proto {
class Derived: Base, Proto {}
return Derived()
public struct S {
public func foo<T>(x: T) -> some Base & Proto {
return Derived()
}
}

// RUN: %sourcekitd-test -req=cursor -pos=5:13 %s -- %s | %FileCheck %s
// CHECK: <Declaration>public func foo() -&gt; some <Type usr=[[Base_USR:.*]]>Base</Type> &amp; <Type usr=[[Proto_USR:.*]]>Proto</Type></Declaration>
// CHECK: <decl.function.free><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>() -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.class usr=[[Base_USR]]>Base</ref.class> &amp; <ref.protocol usr=[[Proto_USR]]>Proto</ref.protocol></decl.function.returntype></decl.function.free>
func test(value: S) {
let _ = value.foo(x: 12)
}

// RUN: %sourcekitd-test -req=cursor -pos=13:15 %s -- %s -module-name Test | %FileCheck %s -check-prefix=DECLSITE
// DECLSITE: source.lang.swift.decl.function.method.instance (13:15-13:27)
// DECLSITE-NEXT: foo(x:)
// DECLSITE-NEXT: s:4Test1SV3foo1xQrx_tlF
// DECLSITE-NEXT: <T> (S) -> (T) -> some Base & Proto
// DECLSITE-NEXT: $s1xQrx_tcluD
// DECLSITE-NEXT: <Declaration>public func foo&lt;T&gt;(x: <Type usr=[[T_USR:.*]]>T</Type>) -&gt; some <Type usr=[[Base_USR:.*]]>Base</Type> &amp; <Type usr=[[Proto_USR:.*]]>Proto</Type></Declaration>
// DECLSITE-NEXT: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>&lt;<decl.generic_type_param usr=[[T_USR]]><decl.generic_type_param.name>T</decl.generic_type_param.name></decl.generic_type_param>&gt;(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.generic_type_param usr=[[T_USR]]>T</ref.generic_type_param></decl.var.parameter.type></decl.var.parameter>) -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.class usr=[[Base_USR]]>Base</ref.class> &amp; <ref.protocol usr=[[Proto_USR]]>Proto</ref.protocol></decl.function.returntype></decl.function.method.instance>

// RUN: %sourcekitd-test -req=cursor -pos=13:43 %s -- %s -module-name Test | %FileCheck %s -check-prefix=PROTO_AFTER_SOME
// PROTO_AFTER_SOME: source.lang.swift.ref.protocol (1:17-1:22)
// PROTO_AFTER_SOME-NEXT: Proto
// PROTO_AFTER_SOME-NEXT: s:4Test5ProtoP
// PROTO_AFTER_SOME-NEXT: Proto.Protocol
// PROTO_AFTER_SOME-NEXT: $s4Test5Proto_pmD
// PROTO_AFTER_SOME-NEXT: <Declaration>public protocol Proto</Declaration>
// PROTO_AFTER_SOME-NEXT: <decl.protocol><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>protocol</syntaxtype.keyword> <decl.name>Proto</decl.name></decl.protocol>

// RUN: %sourcekitd-test -req=cursor -pos=19:17 %s -- %s -module-name Test | %FileCheck %s -check-prefix=USESITE
// USESITE: source.lang.swift.ref.function.method.instance (13:15-13:27)
// USESITE-NEXT: foo(x:)
// USESITE-NEXT: s:4Test1SV3foo1xQrx_tlF
// USESITE-NEXT: <T> (S) -> (T) -> some Base & Proto
// USESITE-NEXT: $s1xQrx_tcluD
// USESITE-NEXT: <Container>$s4Test1SVD</Container>
// USESITE-NEXT: <Declaration>public func foo&lt;T&gt;(x: T) -&gt; some <Type usr=[[Base_USR:.*]]>Base</Type> &amp; <Type usr=[[Proto_USR:.*]]>Proto</Type></Declaration>
// USESITE-NEXT: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>&lt;<decl.generic_type_param usr=[[T_USR:.*]]><decl.generic_type_param.name>T</decl.generic_type_param.name></decl.generic_type_param>&gt;(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type>T</decl.var.parameter.type></decl.var.parameter>) -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.class usr=[[Base_USR]]>Base</ref.class> &amp; <ref.protocol usr=[[Proto_USR]]>Proto</ref.protocol></decl.function.returntype></decl.function.method.instance>