File tree Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -2802,23 +2802,14 @@ namespace {
2802
2802
return simplifyExprType (expr);
2803
2803
}
2804
2804
2805
- Type subExprType = cs.getType (expr->getSubExpr ());
2806
- Type targetType = simplifyType (subExprType);
2807
-
2808
- // If the subexpression is not optional, wrap it in
2809
- // an InjectIntoOptionalExpr. Then use the type of the
2810
- // subexpression as the type of the 'try?' expr
2811
- bool subExprIsOptional = (bool ) subExprType->getOptionalObjectType ();
2812
-
2813
- if (!subExprIsOptional) {
2814
- targetType = OptionalType::get (targetType);
2815
- auto subExpr = coerceToType (expr->getSubExpr (), targetType,
2816
- cs.getConstraintLocator (expr));
2817
- if (!subExpr) return nullptr ;
2818
- expr->setSubExpr (subExpr);
2819
- }
2820
-
2821
- cs.setType (expr, targetType);
2805
+ Type exprType = simplifyType (cs.getType (expr));
2806
+
2807
+ auto subExpr = coerceToType (expr->getSubExpr (), exprType,
2808
+ cs.getConstraintLocator (expr));
2809
+ if (!subExpr) return nullptr ;
2810
+ expr->setSubExpr (subExpr);
2811
+
2812
+ cs.setType (expr, exprType);
2822
2813
return expr;
2823
2814
}
2824
2815
Original file line number Diff line number Diff line change @@ -258,3 +258,14 @@ let _: Int? = try? producer.produceDoubleOptionalInt() // expected-error {{value
258
258
let _: Int ? ? = try ? producer. produceDoubleOptionalInt ( ) // expected-error {{value of optional type 'Int???' not unwrapped; did you mean to use 'try!' or chain with '?'?}}
259
259
let _: Int ? ? ? = try ? producer. produceDoubleOptionalInt ( ) // good
260
260
let _: String = try ? producer. produceDoubleOptionalInt ( ) // expected-error {{cannot convert value of type 'Int???' to specified type 'String'}}
261
+
262
+ // rdar://problem/46742002
263
+ protocol Dummy : class { }
264
+
265
+ class F < T> {
266
+ func wait( ) throws -> T { fatalError ( ) }
267
+ }
268
+
269
+ func bar( _ a: F < Dummy > , _ b: F < Dummy > ) {
270
+ _ = ( try ? a. wait ( ) ) === ( try ? b. wait ( ) )
271
+ }
Original file line number Diff line number Diff line change @@ -261,3 +261,14 @@ let _: Int? = try? producer.produceDoubleOptionalInt() // expected-error {{canno
261
261
let _: Int ? ? = try ? producer. produceDoubleOptionalInt ( ) // good
262
262
let _: Int ? ? ? = try ? producer. produceDoubleOptionalInt ( ) // good
263
263
let _: String = try ? producer. produceDoubleOptionalInt ( ) // expected-error {{cannot convert value of type 'Int??' to specified type 'String'}}
264
+
265
+ // rdar://problem/46742002
266
+ protocol Dummy : class { }
267
+
268
+ class F < T> {
269
+ func wait( ) throws -> T { fatalError ( ) }
270
+ }
271
+
272
+ func bar( _ a: F < Dummy > , _ b: F < Dummy > ) {
273
+ _ = ( try ? a. wait ( ) ) === ( try ? b. wait ( ) )
274
+ }
You can’t perform that action at this time.
0 commit comments