Skip to content

[AST] Look through specializations in getDirectCallee #79631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,13 @@ Expr *CallExpr::getDirectCallee() const {
continue;
}

// Explicit specializations are currently invalid for function calls, but
// look through them for better recovery.
if (auto *spec = dyn_cast<UnresolvedSpecializeExpr>(fn)) {
fn = spec->getSubExpr();
continue;
}

return fn;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/Constraints/rdar145593552.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-typecheck-verify-swift -swift-version 6

// rdar://145593552 - Make sure we don't crash.
func foo(_ x: Int) {} // expected-note {{'foo' declared here}}
foo<Void>("")
// expected-error@-1 {{cannot explicitly specialize global function 'foo'}}
// expected-error@-2 {{cannot convert value of type 'String' to expected argument type 'Int'}}

func bar(x: Int = 0) {} // expected-note {{'bar(x:)' declared here}}
bar<Void>() // expected-error {{cannot explicitly specialize global function 'bar(x:)'}}
8 changes: 4 additions & 4 deletions test/Parse/enum_element_pattern_swift4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ enum E {
case A<UndefinedTy>(): // expected-error {{cannot find type 'UndefinedTy' in scope}}
// expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
// expected-error@-2 {{cannot specialize non-generic type 'E'}}
// expected-error@-3 {{cannot call value of non-function type 'E'}}
// expected-error@-3 {{enum case 'A' has no associated values}}
break
case B<Int>(): // expected-error {{cannot specialize non-generic type 'E'}}
// expected-error@-1 {{cannot call value of non-function type 'E'}}
// expected-error@-1 {{enum case 'B' has no associated values}}
break
default:
break;
Expand All @@ -28,10 +28,10 @@ func testE(e: E) {
case E.A<UndefinedTy>(): // expected-error {{cannot find type 'UndefinedTy' in scope}}
// expected-note@-1 {{while parsing this '<' as a type parameter bracket}}
// expected-error@-2 {{cannot specialize non-generic type 'E'}}
// expected-error@-3 {{cannot call value of non-function type 'E'}}
// expected-error@-3 {{enum case 'A' has no associated values}}
break
case E.B<Int>(): // expected-error {{cannot specialize non-generic type 'E'}}
// expected-error@-1 {{cannot call value of non-function type 'E'}}
// expected-error@-1 {{enum case 'B' has no associated values}}
break
case .C(): // expected-error {{pattern with associated values does not match enum case 'C'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{10-12=}}
Expand Down