File tree 2 files changed +25
-10
lines changed
2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -105,11 +105,20 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
105
105
fixitLoc = originatingDecl->getStartLoc ();
106
106
}
107
107
108
- ctx.Diags .diagnose (repr->getLoc (),
109
- diag::opaque_type_in_protocol_requirement)
110
- .fixItInsert (fixitLoc, " associatedtype <#AssocType#>\n " )
111
- .fixItReplace (repr->getSourceRange (), " <#AssocType#>" );
112
-
108
+ std::string result;
109
+ const char *const placeholder = " <#AssocType#>" ;
110
+ {
111
+ llvm::raw_string_ostream out (result);
112
+ out << " associatedtype " << placeholder << " : " ;
113
+ repr->getConstraint ()->print (out);
114
+ out << " \n " ;
115
+ }
116
+
117
+ ctx.Diags
118
+ .diagnose (repr->getLoc (), diag::opaque_type_in_protocol_requirement)
119
+ .fixItInsert (fixitLoc, result)
120
+ .fixItReplace (repr->getSourceRange (), placeholder);
121
+
113
122
return nullptr ;
114
123
}
115
124
Original file line number Diff line number Diff line change @@ -390,13 +390,19 @@ func rdar_51641323() {
390
390
391
391
// Protocol requirements cannot have opaque return types
392
392
protocol OpaqueProtocolRequirement {
393
- // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>\n}}{{20-26 =<#AssocType#>}}
394
- func method ( ) -> some P
393
+ // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>: P \n}}{{21-27 =<#AssocType#>}}
394
+ func method1 ( ) -> some P
395
395
396
- // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>\n}}{{13-19=<#AssocType#>}}
396
+ // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>: C & P & Q\n}}{{21-35=<#AssocType#>}}
397
+ func method2( ) -> some C & P & Q
398
+
399
+ // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>: Nonsense\n}}{{21-34=<#AssocType#>}}
400
+ func method3( ) -> some Nonsense
401
+
402
+ // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>: P\n}}{{13-19=<#AssocType#>}}
397
403
var prop : some P { get }
398
404
399
- // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>\n}}{{18-24=<#AssocType#>}}
405
+ // expected-error@+1 {{cannot be the return type of a protocol requirement}}{{3-3=associatedtype <#AssocType#>: P \n}}{{18-24=<#AssocType#>}}
400
406
subscript( ) -> some P { get }
401
407
}
402
408
@@ -509,4 +515,4 @@ func takesOpaqueProtocol<T : OpaqueProtocol>(generic: T) {
509
515
_ = generic. asSome
510
516
_ = generic. getAsSome ( )
511
517
_ = generic [ 0 ]
512
- }
518
+ }
You can’t perform that action at this time.
0 commit comments