mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Today ParenType is used: 1. As the type of ParenExpr 2. As the payload type of an unlabeled single associated value enum case (and the type of ParenPattern). 3. As the type for an `(X)` TypeRepr For 1, this leads to some odd behavior, e.g the type of `(5.0 * 5).squareRoot()` is `(Double)`. For 2, we should be checking the arity of the enum case constructor parameters and the presence of ParenPattern respectively. Eventually we ought to consider replacing Paren/TuplePattern with a PatternList node, similar to ArgumentList. 3 is one case where it could be argued that there's some utility in preserving the sugar of the type that the user wrote. However it's really not clear to me that this is particularly desirable since a bunch of diagnostic logic is already stripping ParenTypes. In cases where we care about how the type was written in source, we really ought to be consulting the TypeRepr.
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
// RUN: %target-typecheck-verify-swift -dump-ast > %t.ast
|
|
// RUN: %FileCheck %s < %t.ast
|
|
|
|
// Verify that upcasts of array literals upcast the individual elements in place
|
|
// rather than introducing a collection_upcast_expr.
|
|
|
|
protocol P { }
|
|
struct X : P { }
|
|
|
|
struct TakesArray<T> {
|
|
init(_: [(T) -> Void]) { }
|
|
}
|
|
|
|
// CHECK-LABEL: func_decl{{.*}}"arrayUpcast(_:_:)"
|
|
// CHECK: assign_expr
|
|
// CHECK-NOT: collection_upcast_expr
|
|
// CHECK: array_expr type="[(X) -> Void]"
|
|
// CHECK: function_conversion_expr implicit type="(X) -> Void"
|
|
// CHECK-NEXT: {{declref_expr.*x1}}
|
|
// CHECK-NEXT: function_conversion_expr implicit type="(X) -> Void"
|
|
// CHECK-NEXT: {{declref_expr.*x2}}
|
|
func arrayUpcast(_ x1: @escaping (P) -> Void, _ x2: @escaping (P) -> Void) {
|
|
_ = TakesArray<X>([x1, x2])
|
|
}
|
|
|
|
struct TakesDictionary<T> {
|
|
init(_: [Int : (T) -> Void]) { }
|
|
}
|
|
|
|
// CHECK-LABEL: func_decl{{.*}}"dictionaryUpcast(_:_:)"
|
|
// CHECK: assign_expr
|
|
// CHECK-NOT: collection_upcast_expr
|
|
// CHECK: paren_expr type="[Int : (X) -> Void]"
|
|
// CHECK-NOT: collection_upcast_expr
|
|
// CHECK: (dictionary_expr type="[Int : (X) -> Void]"
|
|
func dictionaryUpcast(_ x1: @escaping (P) -> Void, _ x2: @escaping (P) -> Void) {
|
|
_ = TakesDictionary<X>(([1: x1, 2: x2]))
|
|
}
|