Skip to content
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
12 changes: 11 additions & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,17 @@ NominalTypeDecl *ExtensionDecl::computeExtendedNominal(
if (nominalTypes.empty())
return nullptr;

return nominalTypes[0];
auto *result = nominalTypes[0];

// Tuple extensions are experimental, if the feature isn't enabled let's not
// bind this extension at all. This fixes a bunch of crashers that we don't
// yet properly handle with the feature enabled.
if (isa<BuiltinTupleDecl>(result) &&
!ctx.LangOpts.hasFeature(Feature::TupleConformances)) {
return nullptr;
}

return result;
}

NominalTypeDecl *
Expand Down
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,13 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
return error();
}

// Tuple extensions are experimental.
if (extendedType->is<TupleType>() &&
!ctx.LangOpts.hasFeature(Feature::TupleConformances)) {
diags.diagnose(ext, diag::experimental_tuple_extension);
return error();
}

// Cannot extend function types, metatypes, existentials, etc.
if (!extendedType->is<TupleType>() &&
!extendedType->getAnyNominal() &&
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3652,10 +3652,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
return;

auto &ctx = ED->getASTContext();

if (!ctx.LangOpts.hasFeature(Feature::TupleConformances)) {
ED->diagnose(diag::experimental_tuple_extension);
}
ASSERT(ctx.LangOpts.hasFeature(Feature::TupleConformances) &&
"Extension binding should not have permitted this");

if (!isValidExtendedTypeForTupleExtension(ED)) {
ED->diagnose(diag::tuple_extension_wrong_type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"complete","original":"61e9155a","signature":"swift::ide::CodeCompletionResultBuilder::takeResult()"}
// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
extension ()
where
#^^# == <#type#>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"typecheck","original":"679d3d53","signature":"(anonymous namespace)::PrintAST::visit(swift::Decl*)"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
extension () {
class let a
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"typecheck","signature":"swift::ConditionalRequirementsRequest::evaluate(swift::Evaluator&, swift::NormalProtocolConformance*) const","signatureAssert":"Assertion failed: (typeSig.getCanonicalSignature().getGenericParams() == extensionSig.getCanonicalSignature().getGenericParams()), function evaluate"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
protocol a typealias b<c> = () extension b : a
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// {"kind":"typecheck","signature":"swift::NominalType::get(swift::NominalTypeDecl*, swift::Type, swift::ASTContext const&)","signatureAssert":"Assertion failed: ((!Parent || Parent->is<NominalType>() || Parent->is<BoundGenericType>() || Parent->is<UnboundGenericType>()) && \"parent must be a nominal type\"), function get"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
extension() {
struct a extension a
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"typecheck","original":"2e2249a5","signature":"swift::TypeBase::computeCanonicalType()","signatureAssert":"Assertion failed: (Result->isCanonical()), function computeCanonicalType"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
typealias a<b> = (
>extension a where b == {
c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"typecheck","signature":"(anonymous namespace)::DeclChecker::visit(swift::Decl*)","signatureAssert":"Assertion failed: (false && \"Huh?\"), function isValidExtendedTypeForTupleExtension"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
extension repeat (
12 changes: 12 additions & 0 deletions validation-test/compiler_crashers_2_fixed/966aa8f86a7565d3.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// {"kind":"typecheck","original":"71a26232","signature":"swift::Decl::getDescriptiveKind() const"}
// RUN: not %target-swift-frontend -typecheck %s
typealias a = ()
extension a {
func
< (b: Self, c: Self)
{
for (d, e) in repeat (each b each c) {
d < &e
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// {"kind":"typecheck","signature":"swift::TypeBase::getNominalParent()","signatureAssert":"Assertion failed: (isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"), function cast"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
protocol a {
typealias b<c> = () extension b
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"typecheck","signature":"(anonymous namespace)::DeclChecker::visit(swift::Decl*)","signatureAssert":"Assertion failed: (false && \"Huh?\"), function isValidExtendedTypeForTupleExtension"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
typealias a<b> = (repeat b)protocol c extension a : c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"typecheck","signature":"(anonymous namespace)::DeclChecker::visit(swift::Decl*)","signatureAssert":"Assertion failed: (false && \"Huh?\"), function isValidExtendedTypeForTupleExtension"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
extension(a[ 0.0 b
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"typecheck","signature":"swift::TypeBase::getReducedShape()","signatureAssert":"Assertion failed: (!isTypeVariableOrMember()), function getReducedShape"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
typealias a <b> = ()
extension a {
c {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"typecheck","signature":"swift::BuiltinTupleDecl::getTupleSelfType(swift::ExtensionDecl const*) const","signatureAssert":"Assertion failed: (genericParams->getParams().size() == 1), function getTupleSelfType"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
typealias a<b, c> = () extension a
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// {"kind":"typecheck","signature":"swift::GenericTypeParamType::GenericTypeParamType(swift::GenericTypeParamDecl*, swift::RecursiveTypeProperties)","signatureAssert":"Assertion failed: (param->getDepth() != GenericTypeParamDecl::InvalidDepth), function GenericTypeParamType"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
typealias a = () extension a {
typealias b<c> = () extension b