Files
swift-mirror/test/Constraints/result_builder_generic_infer.swift
Holly Borla 8ba51888c6 [ConstraintSystem] Before applying the result builder transform to a
function body, map the result builder type into context.

This was already done for inferred result builder attributes; now,
the constraint system will map the builder type into context for all
result builder attributes applied to computed properties/functions.
2022-08-29 22:13:13 -07:00

71 lines
2.0 KiB
Swift

// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
protocol P {
associatedtype A
@Builder<A>
var x1: [S] { get }
@Builder<Self>
var x2: [S] { get }
}
@resultBuilder
enum Builder<T> {
static func buildBlock(_ args: S...) -> [S] { args }
}
struct S {}
// CHECK: struct_decl{{.*}}ProtocolSubstitution
struct ProtocolSubstitution: P {
typealias A = Int
// CHECK: var_decl{{.*}}x1
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> Int))
var x1: [S] { S() }
// CHECK: var_decl{{.*}}x2
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> ProtocolSubstitution))
var x2: [S] { S() }
}
// CHECK: struct_decl{{.*}}ArchetypeSubstitution
struct ArchetypeSubstitution<A>: P {
// CHECK: var_decl{{.*}}x1
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> A))
var x1: [S] { S() }
// CHECK: var_decl{{.*}}x2
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> ArchetypeSubstitution<A>))
var x2: [S] { S() }
}
// CHECK-LABEL: struct_decl{{.*}}ExplicitGenericAttribute
struct ExplicitGenericAttribute<T: P> {
// CHECK: var_decl{{.*}}x1
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> T))
@Builder<T>
var x1: [S] { S() }
// CHECK: var_decl{{.*}}x2
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> T.A))
@Builder<T.A>
var x2: [S] { S() }
}
// CHECK: struct_decl{{.*}}ConcreteTypeSubstitution
struct ConcreteTypeSubstitution<Value> {}
extension ConcreteTypeSubstitution: P where Value == Int {
typealias A = Value
// CHECK: var_decl{{.*}}x1
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> Int))
var x1: [S] { S() }
// CHECK: var_decl{{.*}}x2
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> (substitution T -> ConcreteTypeSubstitution<Int>))
var x2: [S] { S() }
}