Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10758,7 +10758,17 @@ and TcNonrecBindingTyparDecls cenv env tpenv bind =
let (NormalizedBinding(_, _, _, _, _, _, synTyparDecls, _, _, _, _, _)) = bind
TcBindingTyparDecls true cenv env tpenv synTyparDecls

and TcNonRecursiveBinding declKind cenv env tpenv ty binding =
and TcNonRecursiveBinding declKind (cenv: cenv) env tpenv ty binding =
// Check for unintended shadowing
if cenv.g.langVersion.SupportsFeature (LanguageFeature.WarnIfFunctionShadowsUnionCase) then
match binding with
| SynBinding(headPat = SynPat.LongIdent(longDotId = SynLongIdent(id = [ident]); range = headPatRange)) ->
match env.eNameResEnv.ePatItems.TryFind ident.idText with
| Some (Item.UnionCase(_, false)) ->
warning(Error(FSComp.SR.tcWarnIfFunctionShadowsUnionCase(), headPatRange))
| _ -> ()
| _ -> ()

let binding = BindingNormalization.NormalizeBinding ValOrMemberBinding cenv env binding
let explicitTyparInfo, tpenv = TcNonrecBindingTyparDecls cenv env tpenv binding
TcNormalizedBinding declKind cenv env tpenv ty None NoSafeInitInfo ([], explicitTyparInfo) binding
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,7 @@ featureChkNotTailRecursive,"Raises warnings if a member or function has the 'Tai
featureWhileBang,"'while!' expression"
featureExtendedFixedBindings,"extended fixed bindings for byref and GetPinnableReference"
featurePreferStringGetPinnableReference,"prefer String.GetPinnableReference in fixed bindings"
featureWarnIfFunctionShadowsUnionCase,"Raises a warning when a function definition shadows a union case"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation."
Expand Down Expand Up @@ -1724,3 +1725,4 @@ featureUnmanagedConstraintCsharpInterop,"Interop between C#'s and F#'s unmanaged
3578,chkCopyUpdateSyntaxInAnonRecords,"This expression is an anonymous record, use {{|...|}} instead of {{...}}."
3579,alwaysUseTypedStringInterpolation,"Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended."
3580,tcUnexpectedFunTypeInUnionCaseField,"Unexpected function type in union case field definition. If you intend the field to be a function, consider wrapping the function signature with parens, e.g. | Case of a -> b into | Case of (a -> b)."
3582,tcWarnIfFunctionShadowsUnionCase,"This is a function definition that shadows a union case. If this is what you want, ignore or suppress this warning. If you want it to be a union case deconstruction, add parantheses."
2 changes: 2 additions & 0 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ open System.Threading
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras

#nowarn "3582" // Remove this line when the Error function is removed as planned below

/// Represents the style being used to format errors
[<RequireQualifiedAccess>]
type DiagnosticStyle =
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type LanguageFeature =
| WhileBang
| ExtendedFixedBindings
| PreferStringGetPinnableReference
| WarnIfFunctionShadowsUnionCase

/// LanguageVersion management
type LanguageVersion(versionText) =
Expand Down Expand Up @@ -185,6 +186,7 @@ type LanguageVersion(versionText) =
// F# preview
LanguageFeature.FromEndSlicing, previewVersion
LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion
LanguageFeature.WarnIfFunctionShadowsUnionCase, previewVersion
]

static let defaultLanguageVersion = LanguageVersion("default")
Expand Down Expand Up @@ -321,6 +323,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.WhileBang -> FSComp.SR.featureWhileBang ()
| LanguageFeature.ExtendedFixedBindings -> FSComp.SR.featureExtendedFixedBindings ()
| LanguageFeature.PreferStringGetPinnableReference -> FSComp.SR.featurePreferStringGetPinnableReference ()
| LanguageFeature.WarnIfFunctionShadowsUnionCase -> FSComp.SR.featureWarnIfFunctionShadowsUnionCase ()

/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type LanguageFeature =
| WhileBang
| ExtendedFixedBindings
| PreferStringGetPinnableReference
| WarnIfFunctionShadowsUnionCase

/// LanguageVersion management
type LanguageVersion =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Service/ServiceLexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ open FSharp.Compiler.Text
open FSharp.Compiler.Text.Position
open FSharp.Compiler.Text.Range

#nowarn "3582" // Don't complain about shadowing the token cases by their tags

module FSharpTokenTag =

let Identifier = tagOfToken (IDENT "a")
Expand Down
10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading