Skip to content

Commit 71fb169

Browse files
committed
[Frontend] Add -warn-on-editor-placeholder
This hidden frontend option lets us be more lax when type-checking in the presence of editor placeholders by treating them as holes during constraint solving.
1 parent 5ea28a7 commit 71fb169

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ namespace swift {
149149
/// Should potential unavailability on enum cases be downgraded to a warning?
150150
bool WarnOnPotentiallyUnavailableEnumCase = false;
151151

152+
/// Should the editor placeholder error be downgraded to a warning?
153+
bool WarnOnEditorPlaceholder = false;
154+
152155
/// Maximum number of typo corrections we are allowed to perform.
153156
/// This is disabled by default until we can get typo-correction working within acceptable performance bounds.
154157
unsigned TypoCorrectionLimit = 0;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ def warn_on_potentially_unavailable_enum_case : Flag<["-"],
462462
"warn-on-potentially-unavailable-enum-case">,
463463
HelpText<"Downgrade potential unavailability of enum case to a warning">;
464464

465+
def warn_on_editor_placeholder : Flag<["-"],
466+
"warn-on-editor-placeholder">,
467+
HelpText<"Downgrade the editor placeholder error to a warning">;
468+
465469
def report_errors_to_debugger : Flag<["-"], "report-errors-to-debugger">,
466470
HelpText<"Deprecated, will be removed in future versions.">;
467471

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
467467

468468
Opts.WarnOnPotentiallyUnavailableEnumCase |=
469469
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
470+
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);
471+
470472
if (auto A = Args.getLastArg(OPT_enable_access_control,
471473
OPT_disable_access_control)) {
472474
Opts.EnableAccessControl

lib/Parse/Lexer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,9 +2145,10 @@ void Lexer::tryLexEditorPlaceholder() {
21452145
if (Ptr[0] == '<' && Ptr[1] == '#')
21462146
break;
21472147
if (Ptr[0] == '#' && Ptr[1] == '>') {
2148-
// Found it. Flag it as error (or warning, if in playground mode) for the
2149-
// rest of the compiler pipeline and lex it as an identifier.
2150-
if (LangOpts.Playground) {
2148+
// Found it. Flag it as error (or warning, if in playground mode or we've
2149+
// been asked to warn) for the rest of the compiler pipeline and lex it
2150+
// as an identifier.
2151+
if (LangOpts.Playground || LangOpts.WarnOnEditorPlaceholder) {
21512152
diagnose(TokStart, diag::lex_editor_placeholder_in_playground);
21522153
} else {
21532154
diagnose(TokStart, diag::lex_editor_placeholder);

0 commit comments

Comments
 (0)