File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -3225,8 +3225,18 @@ namespace {
3225
3225
}
3226
3226
3227
3227
Expr *visitUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *expr) {
3228
- // Our specializations should have resolved the subexpr to the right type.
3229
- return expr->getSubExpr ();
3228
+ // Our specializations should have resolved the subexpr to the right type,
3229
+ // recheck for validity.
3230
+ auto subExpr = expr->getSubExpr ();
3231
+ auto ty = subExpr->getType ();
3232
+ if (ty && !ty->is <AnyMetatypeType>()) {
3233
+ auto &de = cs.getASTContext ().Diags ;
3234
+ de.diagnose (subExpr->getLoc (), diag::not_a_generic_definition);
3235
+ de.diagnose (expr->getLAngleLoc (),
3236
+ diag::while_parsing_as_left_angle_bracket);
3237
+ return nullptr ;
3238
+ }
3239
+ return subExpr;
3230
3240
}
3231
3241
3232
3242
Expr *visitMemberRefExpr (MemberRefExpr *expr) {
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+
3
+ extension Int {
4
+ func foo( ) -> Int { }
5
+ var bar : Int {
6
+ get { }
7
+ }
8
+
9
+ func baz( ) -> Int { }
10
+ func baz( _ x: Int = 0 ) -> Int { }
11
+ }
12
+
13
+ func test( i: Int ) {
14
+ // Error
15
+ let _ = i . foo < Int > ( ) // expected-error {{cannot explicitly specialize a generic function}}
16
+ // expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
17
+ let _ = i. bar< Int> // expected-error {{'>' is not a postfix unary operator}}
18
+
19
+ // Now also Error
20
+ let _ = 0 . foo< Int> ( ) // expected-error {{cannot specialize a non-generic definition}}
21
+ // expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
22
+ let _ = 0 . bar< Int> // expected-error {{'>' is not a postfix unary operator}}
23
+
24
+ let _ = i. baz< Int> // expected-error {{cannot specialize a non-generic definition}}
25
+ // expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
26
+ }
You can’t perform that action at this time.
0 commit comments