Skip to content

Commit 9802425

Browse files
T-GroCopilotCopilot
authored andcommitted
Remove always-on IndexerNotationWithoutDot language feature flag (dotnet#20319)
* Flatten always-on IndexerNotationWithoutDot: remove flag and collapse enforcement sites Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove orphaned IndexerNotationWithoutDot diagnostic strings and regenerate xlf Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Sync xlf files: remove trans-units for FSComp keys deleted in this PR --------- Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: T-Gro <t-gro@users.noreply.github.com>
1 parent be2f84a commit 9802425

20 files changed

Lines changed: 26 additions & 807 deletions

‎src/Compiler/Checking/Expressions/CheckExpressions.fs‎

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ exception FunctionExpected of DisplayEnv * TType * range
5959

6060
exception NotAFunction of DisplayEnv * TType * range * range
6161

62-
exception NotAFunctionButIndexer of DisplayEnv * TType * string option * range * range * bool
62+
exception NotAFunctionButIndexer of DisplayEnv * TType * string option * range * range
6363

6464
exception Recursion of DisplayEnv * Ident * TType * TType * range
6565

@@ -4118,13 +4118,10 @@ let GetInstanceMemberThisVariable (vspec: Val, expr) =
41184118
None
41194119

41204120
/// c.atomicLeftMethExpr[idx] and atomicLeftExpr[idx] as applications give warnings
4121-
let checkHighPrecedenceFunctionApplicationToList (g: TcGlobals) args atomicFlag exprRange =
4121+
let checkHighPrecedenceFunctionApplicationToList args atomicFlag exprRange =
41224122
match args, atomicFlag with
41234123
| ([SynExpr.ArrayOrList (false, _, _)] | [SynExpr.ArrayOrListComputed (false, _, _)]), ExprAtomicFlag.Atomic ->
4124-
if g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
4125-
informationalWarning(Error(FSComp.SR.tcHighPrecedenceFunctionApplicationToListDeprecated(), exprRange))
4126-
elif not (g.langVersion.IsExplicitlySpecifiedAs50OrBefore()) then
4127-
informationalWarning(Error(FSComp.SR.tcHighPrecedenceFunctionApplicationToListReserved(), exprRange))
4124+
informationalWarning(Error(FSComp.SR.tcHighPrecedenceFunctionApplicationToListDeprecated(), exprRange))
41284125
| _ -> ()
41294126

41304127
/// Indicates whether a syntactic type is allowed to include new type variables
@@ -5616,41 +5613,29 @@ and TryTcStmt (cenv: cenv) env tpenv synExpr =
56165613
let hasTypeUnit = TryUnifyUnitTypeWithoutWarning cenv env m ty
56175614
hasTypeUnit, ty, expr, tpenv
56185615

5619-
and CheckForAdjacentListExpression (cenv: cenv) synExpr hpa isInfix delayed (arg: SynExpr) =
5620-
let g = cenv.g
5616+
and CheckForAdjacentListExpression synExpr hpa isInfix delayed (arg: SynExpr) =
56215617
// func (arg)[arg2] gives warning that .[ must be used.
56225618
match delayed with
56235619
| DelayedApp (hpa2, isSugar2, _, arg2, _) :: _ when not isInfix && (hpa = ExprAtomicFlag.NonAtomic) && isAdjacentListExpr isSugar2 hpa2 (Some synExpr) arg2 ->
56245620
let mWarning = unionRanges arg.Range arg2.Range
56255621

56265622
match arg with
56275623
| SynExpr.Paren _ ->
5628-
if g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
5629-
warning(Error(FSComp.SR.tcParenThenAdjacentListArgumentNeedsAdjustment(), mWarning))
5630-
elif not (g.langVersion.IsExplicitlySpecifiedAs50OrBefore()) then
5631-
informationalWarning(Error(FSComp.SR.tcParenThenAdjacentListArgumentReserved(), mWarning))
5624+
warning(Error(FSComp.SR.tcParenThenAdjacentListArgumentNeedsAdjustment(), mWarning))
56325625

56335626
| SynExpr.ArrayOrListComputed _
56345627
| SynExpr.ArrayOrList _ ->
5635-
if g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
5636-
warning(Error(FSComp.SR.tcListThenAdjacentListArgumentNeedsAdjustment(), mWarning))
5637-
elif not (g.langVersion.IsExplicitlySpecifiedAs50OrBefore()) then
5638-
informationalWarning(Error(FSComp.SR.tcListThenAdjacentListArgumentReserved(), mWarning))
5628+
warning(Error(FSComp.SR.tcListThenAdjacentListArgumentNeedsAdjustment(), mWarning))
56395629

56405630
| _ ->
5641-
if g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
5642-
warning(Error(FSComp.SR.tcOtherThenAdjacentListArgumentNeedsAdjustment(), mWarning))
5643-
elif not (g.langVersion.IsExplicitlySpecifiedAs50OrBefore()) then
5644-
informationalWarning(Error(FSComp.SR.tcOtherThenAdjacentListArgumentReserved(), mWarning))
5631+
warning(Error(FSComp.SR.tcOtherThenAdjacentListArgumentNeedsAdjustment(), mWarning))
56455632

56465633
| _ -> ()
56475634

56485635
/// During checking of expressions of the form (x(y)).z(w1, w2)
56495636
/// keep a stack of things on the right. This lets us recognize
56505637
/// method applications and other item-based syntax.
56515638
and TcExprThen (cenv: cenv) overallTy env tpenv isArg synExpr delayed =
5652-
let g = cenv.g
5653-
56545639
let cachedExpression =
56555640
env.eCachedImplicitYieldExpressions.FindAll synExpr.Range
56565641
|> List.tryPick (fun (se, ty, e) ->
@@ -5700,7 +5685,7 @@ and TcExprThen (cenv: cenv) overallTy env tpenv isArg synExpr delayed =
57005685

57015686
TcNonControlFlowExpr env <| fun env ->
57025687

5703-
CheckForAdjacentListExpression cenv synExpr hpa isInfix delayed arg
5688+
CheckForAdjacentListExpression synExpr hpa isInfix delayed arg
57045689

57055690
TcExprThen cenv overallTy env tpenv false func ((DelayedApp (hpa, isInfix, Some func, arg, mFuncAndArg)) :: delayed)
57065691

@@ -5724,7 +5709,7 @@ and TcExprThen (cenv: cenv) overallTy env tpenv isArg synExpr delayed =
57245709
// etc.
57255710
| SynExpr.DotIndexedGet (expr1, IndexerArgs indexArgs, mDot, mWholeExpr) ->
57265711
TcNonControlFlowExpr env <| fun env ->
5727-
if not isArg && g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
5712+
if not isArg then
57285713
informationalWarning(Error(FSComp.SR.tcIndexNotationDeprecated(), mDot))
57295714
TcIndexerThen cenv env overallTy mWholeExpr mDot tpenv None expr1 indexArgs delayed
57305715

@@ -5733,8 +5718,7 @@ and TcExprThen (cenv: cenv) overallTy env tpenv isArg synExpr delayed =
57335718
// etc.
57345719
| SynExpr.DotIndexedSet (expr1, IndexerArgs indexArgs, expr3, mOfLeftOfSet, mDot, mWholeExpr) ->
57355720
TcNonControlFlowExpr env <| fun env ->
5736-
if g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
5737-
warning(Error(FSComp.SR.tcIndexNotationDeprecated(), mDot))
5721+
warning(Error(FSComp.SR.tcIndexNotationDeprecated(), mDot))
57385722
// Wrap in extra parens: like MakeDelayedSet,
57395723
// but we don't actually want to delay it here.
57405724
let setInfo = SynExpr.Paren (expr3, range0, None, expr3.Range), mOfLeftOfSet
@@ -8737,41 +8721,22 @@ and Propagate (cenv: cenv) (overallTy: OverallTy) (env: TcEnv) tpenv (expr: Appl
87378721
// expr[idx1..idx2]
87388722
| SynExpr.ArrayOrListComputed(false, _, _) ->
87398723
let isAdjacent = isAdjacentListExpr isSugar atomicFlag synLeftExprOpt synArg
8740-
if isAdjacent && g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot then
8724+
if isAdjacent then
87418725
// This is the non-error path
87428726
()
87438727
else
8744-
// This is the error path. The error we give depends on what's enabled.
8745-
//
8746-
// First, 'delayed' is about to be dropped on the floor, do rudimentary checking to get name resolutions in its body
8728+
// 'delayed' is about to be dropped on the floor, do rudimentary checking to get name resolutions in its body
87478729
RecordNameAndTypeResolutionsDelayed cenv env tpenv delayed
87488730
let vName =
87498731
match expr.Expr with
87508732
| Expr.Val (d, _, _) -> Some d.DisplayName
87518733
| _ -> None
8752-
if isAdjacent then
8753-
if IsIndexerType g cenv.amap expr.Type then
8754-
if g.langVersion.IsExplicitlySpecifiedAs50OrBefore() then
8755-
error (NotAFunctionButIndexer(denv, overallTy.Commit, vName, mExpr, mArg, false))
8756-
match vName with
8757-
| Some nm ->
8758-
error(Error(FSComp.SR.tcNotAFunctionButIndexerNamedIndexingNotYetEnabled(RichText.mkMember nm, RichText.mkMember nm), mExprAndArg))
8759-
| _ ->
8760-
error(Error(FSComp.SR.tcNotAFunctionButIndexerIndexingNotYetEnabled(), mExprAndArg))
8761-
else
8762-
match vName with
8763-
| Some nm ->
8764-
error(Error(FSComp.SR.tcNotAnIndexerNamedIndexingNotYetEnabled(RichText.mkMember nm), mExprAndArg))
8765-
| _ ->
8766-
error(Error(FSComp.SR.tcNotAnIndexerIndexingNotYetEnabled(), mExprAndArg))
8734+
if IsIndexerType g cenv.amap expr.Type then
8735+
// NotAFunctionButIndexer uses overallTy (expected type) for the indexer suggestion message.
8736+
error (NotAFunctionButIndexer(denv, overallTy.Commit, vName, mExpr, mArg))
87678737
else
8768-
if IsIndexerType g cenv.amap expr.Type then
8769-
let old = not (g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot)
8770-
// NotAFunctionButIndexer uses overallTy (expected type) for the indexer suggestion message.
8771-
error (NotAFunctionButIndexer(denv, overallTy.Commit, vName, mExpr, mArg, old))
8772-
else
8773-
// NotAFunction uses exprTy (actual type) to show "has type X, which does not accept arguments".
8774-
error (NotAFunction(denv, exprTy, mExpr, mArg))
8738+
// NotAFunction uses exprTy (actual type) to show "has type X, which does not accept arguments".
8739+
error (NotAFunction(denv, exprTy, mExpr, mArg))
87758740

87768741
// f x (where 'f' is not a function)
87778742
| _ ->
@@ -9022,7 +8987,7 @@ and TcApplicationThen (cenv: cenv) (overallTy: OverallTy) env tpenv mExprAndArg
90228987

90238988
// atomicLeftExpr[idx] unifying as application gives a warning
90248989
if not isSugar then
9025-
checkHighPrecedenceFunctionApplicationToList g [synArg] atomicFlag mExprAndArg
8990+
checkHighPrecedenceFunctionApplicationToList [synArg] atomicFlag mExprAndArg
90268991

90278992
match leftExpr with
90288993
| ApplicableExpr(expr=NameOfExpr g _) when g.langVersion.SupportsFeature LanguageFeature.NameOf ->
@@ -9091,9 +9056,7 @@ and TcApplicationThen (cenv: cenv) (overallTy: OverallTy) env tpenv mExprAndArg
90919056
// leftExpr[idx]
90929057
// leftExpr[idx] <- expr2
90939058
| SynExpr.ArrayOrListComputed(false, IndexerArgs indexArgs, m)
9094-
when
9095-
isAdjacentListExpr isSugar atomicFlag synLeftExprOpt synArg &&
9096-
g.langVersion.SupportsFeature LanguageFeature.IndexerNotationWithoutDot ->
9059+
when isAdjacentListExpr isSugar atomicFlag synLeftExprOpt synArg ->
90979060

90989061
let expandedIndexArgs = ExpandIndexArgs cenv synLeftExprOpt indexArgs
90999062
let setInfo, delayed =
@@ -10248,7 +10211,7 @@ and TcMethodApplicationThen
1024810211
let mWholeExpr = (m, args) ||> List.fold (fun m arg -> unionRanges m arg.Range)
1024910212

1025010213
// c.atomicLeftMethExpr[idx] as application gives a warning
10251-
checkHighPrecedenceFunctionApplicationToList g args atomicFlag mWholeExpr
10214+
checkHighPrecedenceFunctionApplicationToList args atomicFlag mWholeExpr
1025210215

1025310216
// Work out if we know anything about the return type of the overall expression. If there are any delayed
1025410217
// lookups then we don't know anything.

‎src/Compiler/Checking/Expressions/CheckExpressions.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exception FunctionExpected of DisplayEnv * TType * range
3737

3838
exception NotAFunction of DisplayEnv * TType * range * range
3939

40-
exception NotAFunctionButIndexer of DisplayEnv * TType * string option * range * range * bool
40+
exception NotAFunctionButIndexer of DisplayEnv * TType * string option * range * range
4141

4242
exception Recursion of DisplayEnv * Ident * TType * TType * range
4343

‎src/Compiler/Driver/CompilerDiagnostics.fs‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ type Exception with
179179

180180
| NotAFunction(_, _, mfun, _) -> Some mfun
181181

182-
| NotAFunctionButIndexer(_, _, _, mfun, _, _) -> Some mfun
182+
| NotAFunctionButIndexer(_, _, _, mfun, _) -> Some mfun
183183

184184
| IllegalFileNameChar _ -> Some rangeCmdArgs
185185

@@ -1092,15 +1092,10 @@ type Exception with
10921092

10931093
| InterfaceNotRevealed(denv, intfTy, _) -> os.Append(InterfaceNotRevealedE(), NicePrint.minimalRichTextOfType denv intfTy)
10941094

1095-
| NotAFunctionButIndexer(_, _, name, _, _, old) ->
1096-
if old then
1097-
match name with
1098-
| Some name -> os.Append(FSComp.SR.notAFunctionButMaybeIndexerWithName (RichText.mkLocal name))
1099-
| _ -> os.Append(FSComp.SR.notAFunctionButMaybeIndexer ())
1100-
else
1101-
match name with
1102-
| Some name -> os.Append(FSComp.SR.notAFunctionButMaybeIndexerWithName2 (RichText.mkLocal name))
1103-
| _ -> os.Append(FSComp.SR.notAFunctionButMaybeIndexer2 ())
1095+
| NotAFunctionButIndexer(_, _, name, _, _) ->
1096+
match name with
1097+
| Some name -> os.Append(FSComp.SR.notAFunctionButMaybeIndexerWithName2 (RichText.mkLocal name))
1098+
| _ -> os.Append(FSComp.SR.notAFunctionButMaybeIndexer2 ())
11041099

11051100
| NotAFunction(denv, ty, _, marg) ->
11061101
if marg.StartColumn = 0 then

‎src/Compiler/FSComp.txt‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,6 @@ invalidFullNameForProvidedType,"invalid full name for provided type"
12481248
3087,tcCustomOperationMayNotBeOverloaded,"The custom operation '%s' refers to a method which is overloaded. The implementations of custom operations may not be overloaded."
12491249
featureOverloadsForCustomOperations,"overloads for custom operations"
12501250
featureExpandedMeasurables,"more types support units of measure"
1251-
featureIndexerNotationWithoutDot,"expr[idx] notation for indexing and slicing"
12521251
featureRefCellNotationInformationals,"informational messages related to reference cells"
12531252
featureNonVariablePatternsToRightOfAsPatterns,"non-variable patterns to the right of 'as' patterns"
12541253
featureAttributesToRightOfModuleKeyword,"attributes to the right of the 'module' keyword"
@@ -1484,8 +1483,6 @@ keywordDescriptionUntypedQuotation,"Delimits a untyped code quotation."
14841483
descriptionWordIs,"is"
14851484
notAFunction,"This value is not a function and cannot be applied."
14861485
notAFunctionWithType,"This value is not a function and cannot be applied. It has type '%s', which does not accept arguments."
1487-
notAFunctionButMaybeIndexerWithName,"This value is not a function and cannot be applied. Did you intend to access the indexer via '%s.[index]'?"
1488-
notAFunctionButMaybeIndexer,"This expression is not a function and cannot be applied. Did you intend to access the indexer via 'expr.[index]'?"
14891486
notAFunctionButMaybeIndexerWithName2,"This value is not a function and cannot be applied. Did you intend to access the indexer via '%s[index]'?"
14901487
notAFunctionButMaybeIndexer2,"This expression is not a function and cannot be applied. Did you intend to access the indexer via 'expr[index]'?"
14911488
3217,notAFunctionButMaybeIndexerErrorCode,""
@@ -1603,10 +1600,6 @@ featureEnforceAttributeTargets,"Enforce AttributeTargets"
16031600
featureLowerInterpolatedStringToConcat,"Optimizes interpolated strings in certain cases, by lowering to concatenation"
16041601
featureLowerIntegralRangesToFastLoops,"Optimizes certain uses of the integral range (..) and range-step (.. ..) operators to fast while-loops."
16051602
featureLowerSimpleMappingsInComprehensionsToFastLoops,"Lowers [for x in xs -> f x] and [|for x in xs -> f x|] to fast loops when xs is a list or an array, respectively."
1606-
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
1607-
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
1608-
3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation."
1609-
3355,tcNotAnIndexerIndexingNotYetEnabled,"This expression is not a function and does not support index notation."
16101603
3356,tcDuplicateExtensionMemberNames,"Extension members extending types with the same simple name '%s' but different fully qualified names cannot be defined in the same module. Consider defining these extensions in separate modules."
16111604
3360,typrelInterfaceWithConcreteAndVariable,"'%s' cannot implement the interface '%s' with the two instantiations '%s' and '%s' because they may unify."
16121605
3361,typrelInterfaceWithConcreteAndVariableObjectExpression,"You cannot implement the interface '%s' with the two instantiations '%s' and '%s' because they may unify."
@@ -1615,10 +1608,6 @@ featureLowerSimpleMappingsInComprehensionsToFastLoops,"Lowers [for x in xs -> f
16151608
3364,tcInvalidUseOfReverseIndex,"Invalid use of reverse index in list expression."
16161609
3365,tcHighPrecedenceFunctionApplicationToListDeprecated,"The syntax 'expr1[expr2]' is used for indexing. Consider adding a type annotation to enable indexing, or if calling a function add a space, e.g. 'expr1 [expr2]'."
16171610
3366,tcIndexNotationDeprecated,"The syntax 'arr.[idx]' is now revised to 'arr[idx]'. Please update your code."
1618-
3367,tcHighPrecedenceFunctionApplicationToListReserved,"The syntax 'expr1[expr2]' is now reserved for indexing. See https://aka.ms/fsharp-index-notation. If calling a function, add a space between the function and argument, e.g. 'someFunction [expr]'."
1619-
3368,tcParenThenAdjacentListArgumentReserved,"The syntax '(expr1)[expr2]' is now reserved for indexing and is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction (expr1) [expr2]'."
1620-
3368,tcListThenAdjacentListArgumentReserved,"The syntax '[expr1][expr2]' is now reserved for indexing and is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction [expr1] [expr2]'."
1621-
3368,tcOtherThenAdjacentListArgumentReserved,"The syntax 'expr1[expr2]' is now reserved for indexing and is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction expr1 [expr2]'."
16221611
3369,tcParenThenAdjacentListArgumentNeedsAdjustment,"The syntax '(expr1)[expr2]' is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If you intend indexing or slicing then you must use '(expr1).[expr2]' in argument position. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction (expr1) [expr2]'."
16231612
3369,tcListThenAdjacentListArgumentNeedsAdjustment,"The syntax '[expr1][expr2]' is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If you intend indexing or slicing then you must use '(expr1).[expr2]' in argument position. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction [expr1] [expr2]'."
16241613
3369,tcOtherThenAdjacentListArgumentNeedsAdjustment,"The syntax 'expr1[expr2]' is ambiguous when used as an argument. See https://aka.ms/fsharp-index-notation. If you intend indexing or slicing then you must use 'expr1.[expr2]' in argument position. If calling a function with multiple curried arguments, add a space between them, e.g. 'someFunction expr1 [expr2]'."

0 commit comments

Comments
 (0)