Skip to content

Commit 8227182

Browse files
committed
[TypeChecker] Add Builtin operation to trigger/test fallback diagnostic
(cherry picked from commit 64fa0ee)
1 parent 094a781 commit 8227182

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

include/swift/AST/Builtins.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ BUILTIN_SANITIZER_OPERATION(TSanInoutAccess, "tsanInoutAccess", "")
580580
BUILTIN_TYPE_CHECKER_OPERATION(TypeJoin, type_join)
581581
BUILTIN_TYPE_CHECKER_OPERATION(TypeJoinInout, type_join_inout)
582582
BUILTIN_TYPE_CHECKER_OPERATION(TypeJoinMeta, type_join_meta)
583+
BUILTIN_TYPE_CHECKER_OPERATION(TriggerFallbackDiagnostic, trigger_fallback_diagnostic)
583584

584585
#undef BUILTIN_TYPE_CHECKER_OPERATION
585586

lib/AST/Builtins.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,12 @@ static ValueDecl *getTypeJoinMetaOperation(ASTContext &Context, Identifier Id) {
10101010
return builder.build(Id);
10111011
}
10121012

1013+
static ValueDecl *getTriggerFallbackDiagnosticOperation(ASTContext &Context,
1014+
Identifier Id) {
1015+
// () -> Void
1016+
return getBuiltinFunction(Id, {}, Context.TheEmptyTupleType);
1017+
}
1018+
10131019
static ValueDecl *getCanBeObjCClassOperation(ASTContext &Context,
10141020
Identifier Id) {
10151021
// <T> T.Type -> Builtin.Int8
@@ -1899,7 +1905,10 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
18991905
return getTypeJoinInoutOperation(Context, Id);
19001906

19011907
case BuiltinValueKind::TypeJoinMeta:
1902-
return getTypeJoinMetaOperation(Context, Id);
1908+
return getTypeJoinMetaOperation(Context, Id);
1909+
1910+
case BuiltinValueKind::TriggerFallbackDiagnostic:
1911+
return getTriggerFallbackDiagnosticOperation(Context, Id);
19031912
}
19041913

19051914
llvm_unreachable("bad builtin value!");

lib/Sema/CSGen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,11 @@ namespace {
15791579
if (typeOperation != TypeOperation::None)
15801580
return CS.getASTContext().TheAnyType;
15811581

1582+
// If this is `Builtin.trigger_fallback_diagnostic()`, fail
1583+
// without producing any diagnostics, in order to test fallback error.
1584+
if (isTriggerFallbackDiagnosticBuiltin(expr, CS.getASTContext()))
1585+
return nullptr;
1586+
15821587
// Open a member constraint for constructor delegations on the
15831588
// subexpr type.
15841589
if (CS.TC.getSelfForInitDelegationInConstructor(CS.DC, expr)) {
@@ -3128,6 +3133,19 @@ namespace {
31283133
return tv;
31293134
}
31303135

3136+
static bool isTriggerFallbackDiagnosticBuiltin(UnresolvedDotExpr *UDE,
3137+
ASTContext &Context) {
3138+
auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase());
3139+
if (!DRE)
3140+
return false;
3141+
3142+
if (DRE->getDecl() != Context.TheBuiltinModule)
3143+
return false;
3144+
3145+
auto member = UDE->getName().getBaseIdentifier().str();
3146+
return member.equals("trigger_fallback_diagnostic");
3147+
}
3148+
31313149
enum class TypeOperation { None,
31323150
Join,
31333151
JoinInout,

test/Sema/rdar38885760.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: not %target-swift-frontend -typecheck %s -parse-stdlib 2>%t/fallback_diagnostic.txt
4+
// RUN: %FileCheck %s --check-prefix FALLBACK-DIAGNOSTIC <%t/fallback_diagnostic.txt
5+
//
6+
// FALLBACK-DIAGNOSTIC: error: failed to produce diagnostic for expression; please file a bug report with your project
7+
8+
import Swift
9+
10+
Builtin.trigger_fallback_diagnostic()

0 commit comments

Comments
 (0)