Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion unified/extractor/src/languages/swift/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
modifier: {late}
type: {base})
),
rule!(
(someOrAnyType someOrAnySpecifier: @@spec constraint: @constraint)
=>
(modified_type_expr
modifier: (modifier #{spec})
type: {constraint})
),
// Preserve the `super` keyword as a dedicated expression, normally used
// as the base of a member access (`super.foo`).
rule!((superExpr) => (super_expr)),
Expand Down Expand Up @@ -1540,7 +1547,6 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
rule!((postfixIfConfigExpr) => (unsupported_node "")),
rule!((poundSourceLocation) => (unsupported_node "")),
rule!((precedenceGroupDecl) => (unsupported_node "")),
rule!((someOrAnyType) => (unsupported_node "")),
rule!((subscriptDecl) => (unsupported_node "")),
rule!((suppressedType) => (unsupported_node "")),
rule!((typeExpr) => (unsupported_node "")),
Expand Down
75 changes: 75 additions & 0 deletions unified/extractor/tests/corpus/swift/types/any-type.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
let values: any Collection<Int> = [1, 2]

---

sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
variableDecl
attributes:
modifiers:
bindingSpecifier: let
bindings:
patternBinding
initializer:
initializerClause
equal: =
value:
arrayExpr
elements:
arrayElement
expression:
integerLiteralExpr
literal: integerLiteral "1"
trailingComma: ,
arrayElement
expression:
integerLiteralExpr
literal: integerLiteral "2"
leftSquare: [
rightSquare: ]
pattern:
identifierPattern
identifier: identifier "values"
typeAnnotation:
typeAnnotation
colon: :
type:
someOrAnyType
constraint:
identifierType
name: identifier "Collection"
genericArgumentClause:
genericArgumentClause
arguments:
genericArgument
argument:
identifierType
name: identifier "Int"
leftAngle: <
rightAngle: >
someOrAnySpecifier: any

---

top_level source="⟨body⟩"
body:
block source="⟨stmt⟩"
stmt:
variable_declaration source="⟨modifier⟩ ⟨pattern⟩: ⟨type⟩ = ⟨value⟩"
modifier: modifier "let" source="let"
pattern: identifier "values" source="values"
type:
modified_type_expr source="⟨modifier⟩ ⟨type⟩"
modifier: modifier "any" source="any"
type:
generic_type_expr source="⟨base⟩<⟨type_argument⟩>"
base: identifier "Collection" source="Collection"
type_argument: identifier "Int" source="Int"
value:
array_literal source="[⟨element⟩, ⟨element⟩]"
element:
int_literal "1" source="1"
int_literal "2" source="2"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let values: any Collection<Int> = [1, 2]
101 changes: 101 additions & 0 deletions unified/extractor/tests/corpus/swift/types/some-type.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
func values(_ input: some Collection<Int>) -> some Collection<Int> {
input
}

---

sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
functionDecl
attributes:
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
codeBlockItem
item:
declReferenceExpr
baseName: identifier "input"
modifiers:
name: identifier "values"
signature:
functionSignature
parameterClause:
functionParameterClause
leftParen: (
rightParen: )
parameters:
functionParameter
colon: :
attributes:
modifiers:
type:
someOrAnyType
constraint:
identifierType
name: identifier "Collection"
genericArgumentClause:
genericArgumentClause
arguments:
genericArgument
argument:
identifierType
name: identifier "Int"
leftAngle: <
rightAngle: >
someOrAnySpecifier: some
firstName: _
secondName: identifier "input"
returnClause:
returnClause
arrow: ->
type:
someOrAnyType
constraint:
identifierType
name: identifier "Collection"
genericArgumentClause:
genericArgumentClause
arguments:
genericArgument
argument:
identifierType
name: identifier "Int"
leftAngle: <
rightAngle: >
someOrAnySpecifier: some
funcKeyword: func

---

top_level source="⟨body⟩"
body:
block source="⟨stmt⟩"
stmt:
function_declaration source="func ⟨name_node⟩(⟨parameter⟩) -> ⟨return_type⟩ ⟨body⟩"
name_node: identifier "values" source="values"
parameter:
parameter source="⟨external_name_node⟩ ⟨pattern⟩: ⟨type⟩"
external_name_node: identifier "_" source="_"
type:
modified_type_expr source="⟨modifier⟩ ⟨type⟩"
modifier: modifier "some" source="some"
type:
generic_type_expr source="⟨base⟩<⟨type_argument⟩>"
base: identifier "Collection" source="Collection"
type_argument: identifier "Int" source="Int"
pattern: identifier "input" source="input"
return_type:
modified_type_expr source="⟨modifier⟩ ⟨type⟩"
modifier: modifier "some" source="some"
type:
generic_type_expr source="⟨base⟩<⟨type_argument⟩>"
base: identifier "Collection" source="Collection"
type_argument: identifier "Int" source="Int"
body:
block source="{\n ⟨stmt⟩\n}"
stmt: identifier "input" source="input"
3 changes: 3 additions & 0 deletions unified/extractor/tests/corpus/swift/types/some-type.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func values(_ input: some Collection<Int>) -> some Collection<Int> {
input
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct IntPrimaryAssociatedType: PrimaryAssociatedTypeProtocol {
}

func getPrimaryAssociatedType(_ value: some PrimaryAssociatedTypeProtocol<Int>) -> Int {
return value.element() // $ MISSING: target=PrimaryAssociatedTypeProtocol.element
return value.element() // $ target=PrimaryAssociatedTypeProtocol.element
}

func testPrimaryAssociatedType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ inferCertainType
| generics.swift:253:10:253:10 | c | | generics.swift:252:14:252:27 | T |
| generics.swift:287:65:287:69 | value | | generics.swift:287:33:287:60 | T |
| generics.swift:288:10:288:14 | value | | generics.swift:287:33:287:60 | T |
| generics.swift:311:33:311:37 | value | | generics.swift:297:1:301:1 | PrimaryAssociatedTypeProtocol |
| generics.swift:312:10:312:14 | value | | generics.swift:297:1:301:1 | PrimaryAssociatedTypeProtocol |
| generics.swift:319:5:319:5 | x | | {EXTERNAL LOCATION} | Array |
| generics.swift:319:16:319:21 | ArrayLiteral | | {EXTERNAL LOCATION} | Array |
| key_paths.swift:4:7:4:7 | x | | {EXTERNAL LOCATION} | Double |
Expand Down Expand Up @@ -2542,6 +2544,8 @@ inferType
| generics.swift:292:42:292:63 | StringAssociatedType(...) | | generics.swift:275:1:285:1 | StringAssociatedType |
| generics.swift:306:25:308:3 | Block | | {EXTERNAL LOCATION} | Int |
| generics.swift:307:12:307:13 | 42 | | {EXTERNAL LOCATION} | Int |
| generics.swift:311:33:311:37 | value | | generics.swift:297:1:301:1 | PrimaryAssociatedTypeProtocol |
| generics.swift:312:10:312:14 | value | | generics.swift:297:1:301:1 | PrimaryAssociatedTypeProtocol |
| generics.swift:316:7:316:11 | value | | {EXTERNAL LOCATION} | Int |
| generics.swift:316:15:316:66 | getPrimaryAssociatedType(...) | | {EXTERNAL LOCATION} | Int |
| generics.swift:316:40:316:63 | IntPrimaryAssociatedType | | generics.swift:303:1:309:1 | IntPrimaryAssociatedType |
Expand Down
Loading