Skip to content

Commit 714c862

Browse files
authored
Merge pull request #79631 from hamishknight/up-to-spec
[AST] Look through specializations in `getDirectCallee`
2 parents 361473c + 96ae3fd commit 714c862

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/AST/Expr.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,13 @@ Expr *CallExpr::getDirectCallee() const {
17531753
continue;
17541754
}
17551755

1756+
// Explicit specializations are currently invalid for function calls, but
1757+
// look through them for better recovery.
1758+
if (auto *spec = dyn_cast<UnresolvedSpecializeExpr>(fn)) {
1759+
fn = spec->getSubExpr();
1760+
continue;
1761+
}
1762+
17561763
return fn;
17571764
}
17581765
}

test/Constraints/rdar145593552.swift

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
// rdar://145593552 - Make sure we don't crash.
4+
func foo(_ x: Int) {} // expected-note {{'foo' declared here}}
5+
foo<Void>("")
6+
// expected-error@-1 {{cannot explicitly specialize global function 'foo'}}
7+
// expected-error@-2 {{cannot convert value of type 'String' to expected argument type 'Int'}}
8+
9+
func bar(x: Int = 0) {} // expected-note {{'bar(x:)' declared here}}
10+
bar<Void>() // expected-error {{cannot explicitly specialize global function 'bar(x:)'}}

test/Parse/enum_element_pattern_swift4.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ enum E {
1212
case A<UndefinedTy>(): // expected-error {{cannot find type 'UndefinedTy' in scope}}
1313
// expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
1414
// expected-error@-2 {{cannot specialize non-generic type 'E'}}
15-
// expected-error@-3 {{cannot call value of non-function type 'E'}}
15+
// expected-error@-3 {{enum case 'A' has no associated values}}
1616
break
1717
case B<Int>(): // expected-error {{cannot specialize non-generic type 'E'}}
18-
// expected-error@-1 {{cannot call value of non-function type 'E'}}
18+
// expected-error@-1 {{enum case 'B' has no associated values}}
1919
break
2020
default:
2121
break;
@@ -28,10 +28,10 @@ func testE(e: E) {
2828
case E.A<UndefinedTy>(): // expected-error {{cannot find type 'UndefinedTy' in scope}}
2929
// expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
3030
// expected-error@-2 {{cannot specialize non-generic type 'E'}}
31-
// expected-error@-3 {{cannot call value of non-function type 'E'}}
31+
// expected-error@-3 {{enum case 'A' has no associated values}}
3232
break
3333
case E.B<Int>(): // expected-error {{cannot specialize non-generic type 'E'}}
34-
// expected-error@-1 {{cannot call value of non-function type 'E'}}
34+
// expected-error@-1 {{enum case 'B' has no associated values}}
3535
break
3636
case .C(): // expected-error {{pattern with associated values does not match enum case 'C'}}
3737
// expected-note@-1 {{remove associated values to make the pattern match}} {{10-12=}}

0 commit comments

Comments
 (0)