diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 4599cc79f62f..70d99e616c15 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -1213,6 +1213,13 @@ fn translation_rules() -> Vec> { 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)), @@ -1540,7 +1547,6 @@ fn translation_rules() -> Vec> { 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 "")), diff --git a/unified/extractor/tests/corpus/swift/types/any-type.output b/unified/extractor/tests/corpus/swift/types/any-type.output new file mode 100644 index 000000000000..92862f73c715 --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/any-type.output @@ -0,0 +1,75 @@ +let values: any Collection = [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" diff --git a/unified/extractor/tests/corpus/swift/types/any-type.swift b/unified/extractor/tests/corpus/swift/types/any-type.swift new file mode 100644 index 000000000000..c7d08e67311e --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/any-type.swift @@ -0,0 +1 @@ +let values: any Collection = [1, 2] diff --git a/unified/extractor/tests/corpus/swift/types/some-type.output b/unified/extractor/tests/corpus/swift/types/some-type.output new file mode 100644 index 000000000000..5161bc40643a --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/some-type.output @@ -0,0 +1,101 @@ +func values(_ input: some Collection) -> some Collection { + 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" diff --git a/unified/extractor/tests/corpus/swift/types/some-type.swift b/unified/extractor/tests/corpus/swift/types/some-type.swift new file mode 100644 index 000000000000..c54055c4f47b --- /dev/null +++ b/unified/extractor/tests/corpus/swift/types/some-type.swift @@ -0,0 +1,3 @@ +func values(_ input: some Collection) -> some Collection { + input +} diff --git a/unified/ql/test/library-tests/type-inference/generics.swift b/unified/ql/test/library-tests/type-inference/generics.swift index d5ed2bf20c0f..89353bd7a989 100644 --- a/unified/ql/test/library-tests/type-inference/generics.swift +++ b/unified/ql/test/library-tests/type-inference/generics.swift @@ -309,7 +309,7 @@ struct IntPrimaryAssociatedType: PrimaryAssociatedTypeProtocol { } func getPrimaryAssociatedType(_ value: some PrimaryAssociatedTypeProtocol) -> Int { - return value.element() // $ MISSING: target=PrimaryAssociatedTypeProtocol.element + return value.element() // $ target=PrimaryAssociatedTypeProtocol.element } func testPrimaryAssociatedType() { diff --git a/unified/ql/test/library-tests/type-inference/type-inference.expected b/unified/ql/test/library-tests/type-inference/type-inference.expected index e978a676689b..124272f5137e 100644 --- a/unified/ql/test/library-tests/type-inference/type-inference.expected +++ b/unified/ql/test/library-tests/type-inference/type-inference.expected @@ -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 | @@ -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 |