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 @@ -2825,23 +2825,14 @@ namespace {
2825
2825
return simplifyExprType (expr);
2826
2826
}
2827
2827
2828
- Type subExprType = cs.getType (expr->getSubExpr ());
2829
- Type targetType = simplifyType (subExprType);
2830
-
2831
- // If the subexpression is not optional, wrap it in
2832
- // an InjectIntoOptionalExpr. Then use the type of the
2833
- // subexpression as the type of the 'try?' expr
2834
- bool subExprIsOptional = (bool ) subExprType->getOptionalObjectType ();
2835
-
2836
- if (!subExprIsOptional) {
2837
- targetType = OptionalType::get (targetType);
2838
- auto subExpr = coerceToType (expr->getSubExpr (), targetType,
2839
- cs.getConstraintLocator (expr));
2840
- if (!subExpr) return nullptr ;
2841
- expr->setSubExpr (subExpr);
2842
- }
2843
-
2844
- cs.setType (expr, targetType);
2828
+ Type exprType = simplifyType (cs.getType (expr));
2829
+
2830
+ auto subExpr = coerceToType (expr->getSubExpr (), exprType,
2831
+ cs.getConstraintLocator (expr));
2832
+ if (!subExpr) return nullptr ;
2833
+ expr->setSubExpr (subExpr);
2834
+
2835
+ cs.setType (expr, exprType);
2845
2836
return expr;
2846
2837
}
2847
2838
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