Skip to content

Parse: Relax a recently-added assertion #11256

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
Jul 29, 2017
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: 6 additions & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,12 @@ Expr *Parser::parseExprIdentifier() {
auto refKind = DeclRefKind::Ordinary;
E = new (Context) UnresolvedDeclRefExpr(name, refKind, loc);
} else if (auto TD = dyn_cast<TypeDecl>(D)) {
assert(!TD->getDeclContext()->isTypeContext());
// When parsing default argument expressions for generic functions,
// we haven't built a FuncDecl or re-parented the GenericTypeParamDecls
// to the FuncDecl yet. Other than that, we should only ever find
// global or local declarations here.
assert(!TD->getDeclContext()->isTypeContext() ||
isa<GenericTypeParamDecl>(TD));
E = TypeExpr::createForDecl(loc.getBaseNameLoc(), TD, /*DC*/nullptr,
/*implicit*/false);
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/decl/func/default-values-swift4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ public func publicFunctionWithDefaultValue(
}(),
y: Int = internalIntFunction()) {}
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}

// https://bugs.swift.org/browse/SR-5559
public class MyClass {
public func method<T>(_: T.Type = T.self) -> T { }
}