Skip to content

Commit f396f39

Browse files
committed
Frontend: Do not suggest mode correction if adoption is not supported
1 parent 1bfe193 commit f396f39

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ GROUPED_WARNING(feature_not_experimental, StrictLanguageFeatures, DefaultIgnore,
5151
(StringRef, bool))
5252

5353
GROUPED_WARNING(invalid_feature_mode, StrictLanguageFeatures, none,
54-
"'%0' is not a recognized mode for feature '%1'; "
55-
"did you mean '%2'?",
56-
(StringRef, StringRef, StringRef))
54+
"'%0' is not a recognized mode for feature '%1'"
55+
"%select{|; did you mean '%2'?}3",
56+
(StringRef, StringRef, StringRef, bool))
5757

5858
GROUPED_WARNING(cannot_disable_feature_with_mode, StrictLanguageFeatures, none,
5959
"'%0' argument '%1' cannot specify a mode",

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,16 +823,19 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
823823

824824
if (featureMode) {
825825
if (isEnableFeatureFlag) {
826+
const auto isAdoptable = isFeatureAdoptable(*feature);
827+
826828
// Diagnose an invalid mode.
827829
StringRef validModeName = "adoption";
828830
if (*featureMode != validModeName) {
829831
Diags.diagnose(SourceLoc(), diag::invalid_feature_mode, *featureMode,
830832
featureName,
831-
/*didYouMean=*/validModeName);
833+
/*didYouMean=*/validModeName,
834+
/*showDidYouMean=*/isAdoptable);
832835
continue;
833836
}
834837

835-
if (!isFeatureAdoptable(*feature)) {
838+
if (!isAdoptable) {
836839
Diags.diagnose(SourceLoc(),
837840
diag::feature_does_not_support_adoption_mode,
838841
featureName);

test/Frontend/strict_features_adoption_mode.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
// CHECK-SWIFT-5-NEXT: warning: '-disable-upcoming-feature' argument 'DynamicActorIsolation:invalid5' cannot specify a mode{{$}}
4343
// CHECK-SWIFT-5-NEXT: warning: feature 'DynamicActorIsolation' does not support adoption mode{{$}}
4444
// CHECK-SWIFT-5-NEXT: warning: feature 'DynamicActorIsolation' does not support adoption mode{{$}}
45-
// CHECK-SWIFT-5-NEXT: warning: 'invalid4' is not a recognized mode for feature 'DynamicActorIsolation'; did you mean 'adoption'?{{$}}
46-
// CHECK-SWIFT-5-NEXT: warning: 'invalid3' is not a recognized mode for feature 'DynamicActorIsolation'; did you mean 'adoption'?{{$}}
45+
// CHECK-SWIFT-5-NEXT: warning: 'invalid4' is not a recognized mode for feature 'DynamicActorIsolation'{{$}}
46+
// CHECK-SWIFT-5-NEXT: warning: 'invalid3' is not a recognized mode for feature 'DynamicActorIsolation'{{$}}
4747
// CHECK-SWIFT-5-NEXT: warning: feature 'DynamicActorIsolation' does not support adoption mode{{$}}
4848
// CHECK-SWIFT-5-NEXT: warning: feature 'DynamicActorIsolation' does not support adoption mode{{$}}
49-
// CHECK-SWIFT-5-NEXT: warning: 'invalid2' is not a recognized mode for feature 'DynamicActorIsolation'; did you mean 'adoption'?{{$}}
50-
// CHECK-SWIFT-5-NEXT: warning: 'invalid1' is not a recognized mode for feature 'DynamicActorIsolation'; did you mean 'adoption'?{{$}}
49+
// CHECK-SWIFT-5-NEXT: warning: 'invalid2' is not a recognized mode for feature 'DynamicActorIsolation'{{$}}
50+
// CHECK-SWIFT-5-NEXT: warning: 'invalid1' is not a recognized mode for feature 'DynamicActorIsolation'{{$}}
5151
// CHECK-SWIFT-5-NOT: warning:
5252

5353
// CHECK-SWIFT-6-NOT: warning:

0 commit comments

Comments
 (0)