Skip to content

Commit adf811c

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 3e8204d commit adf811c

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
@@ -128,6 +128,9 @@ namespace swift {
128128
/// Should potential unavailability on enum cases be downgraded to a warning?
129129
bool WarnOnPotentiallyUnavailableEnumCase = false;
130130

131+
/// Should the editor placeholder error be downgraded to a warning?
132+
bool WarnOnEditorPlaceholder = false;
133+
131134
/// Maximum number of typo corrections we are allowed to perform.
132135
/// This is disabled by default until we can get typo-correction working within acceptable performance bounds.
133136
unsigned TypoCorrectionLimit = 0;

include/swift/Option/FrontendOptions.td

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

439+
def warn_on_editor_placeholder : Flag<["-"],
440+
"warn-on-editor-placeholder">,
441+
HelpText<"Downgrade the editor placeholder error to a warning">;
442+
439443
def report_errors_to_debugger : Flag<["-"], "report-errors-to-debugger">,
440444
HelpText<"Deprecated, will be removed in future versions.">;
441445

lib/Frontend/CompilerInvocation.cpp

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

427427
Opts.WarnOnPotentiallyUnavailableEnumCase |=
428428
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
429+
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);
430+
429431
if (auto A = Args.getLastArg(OPT_enable_access_control,
430432
OPT_disable_access_control)) {
431433
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)