Skip to content

Commit a24a439

Browse files
authored
Merge pull request #11256 from slavapestov/relax-an-assert
Parse: Relax a recently-added assertion
2 parents 9b91803 + 36d4384 commit a24a439

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,12 @@ Expr *Parser::parseExprIdentifier() {
20672067
auto refKind = DeclRefKind::Ordinary;
20682068
E = new (Context) UnresolvedDeclRefExpr(name, refKind, loc);
20692069
} else if (auto TD = dyn_cast<TypeDecl>(D)) {
2070-
assert(!TD->getDeclContext()->isTypeContext());
2070+
// When parsing default argument expressions for generic functions,
2071+
// we haven't built a FuncDecl or re-parented the GenericTypeParamDecls
2072+
// to the FuncDecl yet. Other than that, we should only ever find
2073+
// global or local declarations here.
2074+
assert(!TD->getDeclContext()->isTypeContext() ||
2075+
isa<GenericTypeParamDecl>(TD));
20712076
E = TypeExpr::createForDecl(loc.getBaseNameLoc(), TD, /*DC*/nullptr,
20722077
/*implicit*/false);
20732078
} else {

test/decl/func/default-values-swift4.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ public func publicFunctionWithDefaultValue(
7878
}(),
7979
y: Int = internalIntFunction()) {}
8080
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}
81+
82+
// https://bugs.swift.org/browse/SR-5559
83+
public class MyClass {
84+
public func method<T>(_: T.Type = T.self) -> T { }
85+
}

0 commit comments

Comments
 (0)