Skip to content

Commit 63ba102

Browse files
authored
Merge branch 'main' into allow-and-bang-typed-bindings
2 parents 4cecf5e + 9fab712 commit 63ba102

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+392
-288
lines changed

docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
88
* Fix parsing errors using anonymous records and code quotations ([PR #18603](https://github.com/dotnet/fsharp/pull/18603))
9+
* Better error message for attribute targets. ([PR #18641](https://github.com/dotnet/fsharp/pull/18641))
910
* Fixed: Allow `return`, `return!`, `yield`, `yield!` type annotations without parentheses ([PR #18533](https://github.com/dotnet/fsharp/pull/18533))
1011
* Allow `let!`, `use!`, `and!` type annotations without requiring parentheses (([PR #18508](https://github.com/dotnet/fsharp/pull/18508) and [PR #18682](https://github.com/dotnet/fsharp/pull/18682)))
1112
* Fix find all references for F# exceptions ([PR #18565](https://github.com/dotnet/fsharp/pull/18565))

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
</Dependency>
3737
</ProductDependencies>
3838
<ToolsetDependencies>
39-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="10.0.0-beta.25326.3">
39+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="10.0.0-beta.25358.3">
4040
<Uri>https://github.com/dotnet/arcade</Uri>
41-
<Sha>0e335649fe2d2f98ea51e55cc1a0899af3617eba</Sha>
41+
<Sha>4e526204e83e615efe8eb5743be7fbccfa4e492a</Sha>
4242
</Dependency>
4343
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.25324.1">
4444
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"perl": "5.38.2.2"
2323
},
2424
"msbuild-sdks": {
25-
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25326.3",
25+
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25358.3",
2626
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
2727
}
2828
}

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ exception StandardOperatorRedefinitionWarning of string * range
143143

144144
exception InvalidInternalsVisibleToAssemblyName of badName: string * fileName: string option
145145

146+
exception InvalidAttributeTargetForLanguageElement of elementTargets: string array * allowedTargets: string array * range: range
147+
146148
//----------------------------------------------------------------------------------------------
147149
// Helpers for determining if/what specifiers a string has.
148150
// Used to decide if interpolated string can be lowered to a concat call.
@@ -11356,7 +11358,29 @@ and CheckAttributeUsage (g: TcGlobals) (mAttr: range) (tcref: TyconRef) (attrTgt
1135611358
if (directedTargets = AttributeTargets.Assembly || directedTargets = AttributeTargets.Module) then
1135711359
errorR(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElementUseDo(), mAttr))
1135811360
else
11359-
warning(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElement(), mAttr))
11361+
let attributeTargetsToString (targets: int) =
11362+
[|
11363+
if targets &&& int AttributeTargets.Assembly <> 0 then "assembly"
11364+
if targets &&& int AttributeTargets.Module <> 0 then "module"
11365+
if targets &&& int AttributeTargets.Class <> 0 then "class"
11366+
if targets &&& int AttributeTargets.Struct <> 0 then "struct"
11367+
if targets &&& int AttributeTargets.Enum <> 0 then "enum"
11368+
if targets &&& int AttributeTargets.Constructor <> 0 then "constructor"
11369+
if targets &&& int AttributeTargets.Method <> 0 then "method"
11370+
if targets &&& int AttributeTargets.Property <> 0 then "property"
11371+
if targets &&& int AttributeTargets.Field <> 0 then "field"
11372+
if targets &&& int AttributeTargets.Event <> 0 then "event"
11373+
if targets &&& int AttributeTargets.Interface <> 0 then "interface"
11374+
if targets &&& int AttributeTargets.Parameter <> 0 then "parameter"
11375+
if targets &&& int AttributeTargets.Delegate <> 0 then "delegate"
11376+
if targets &&& int AttributeTargets.ReturnValue <> 0 then "return value"
11377+
if targets &&& int AttributeTargets.GenericParameter <> 0 then "type parameter"
11378+
|]
11379+
11380+
let elementTargets = attributeTargetsToString (int attrTgt)
11381+
let allowedTargets = attributeTargetsToString validOn
11382+
11383+
warning(InvalidAttributeTargetForLanguageElement(elementTargets, allowedTargets, mAttr))
1136011384

1136111385
constrainedTargets
1136211386

src/Compiler/Checking/Expressions/CheckExpressions.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ exception StandardOperatorRedefinitionWarning of string * range
121121

122122
exception InvalidInternalsVisibleToAssemblyName of badName: string * fileName: string option
123123

124+
exception InvalidAttributeTargetForLanguageElement of
125+
elementTargets: string array *
126+
allowedTargets: string array *
127+
range: range
128+
124129
val TcFieldInit: range -> ILFieldInit -> Const
125130

126131
/// Indicates whether a syntactic type is allowed to include new type variables

src/Compiler/Checking/NicePrint.fs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,10 @@ module PrintTastMemberOrVals =
14131413
if short then
14141414
tauL --- withGet
14151415
else
1416-
let nameL = layoutMemberName denv vref niceMethodTypars argInfos tagProperty vref.DisplayNameCoreMangled prefixAccessModifier
1416+
let prefixAccess = prefixAccessModifier || isNil argInfos
1417+
let nameL = layoutMemberName denv vref niceMethodTypars argInfos tagProperty vref.DisplayNameCoreMangled prefixAccess
14171418
let nameL = if short then nameL else mkInlineL denv vref.Deref nameL
1418-
stat --- ((nameL |> addColonL) ^^ (if isNil argInfos && not supportAccessModifiersBeforeGetSet then tauL else tauL --- withGet))
1419+
stat --- ((nameL |> addColonL) ^^ (if isNil argInfos then tauL else (tauL --- withGet)))
14191420
prettyTyparInst, resL
14201421

14211422
| SynMemberKind.PropertySet ->
@@ -1927,11 +1928,8 @@ module TastDefinitionPrinting =
19271928
let layoutPropInfo denv (infoReader: InfoReader) m (pinfo: PropInfo) : Layout list =
19281929
let amap = infoReader.amap
19291930

1930-
let supportAccessModifiersBeforeGetSet =
1931-
denv.g.langVersion.SupportsFeature Features.LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters
1932-
19331931
match pinfo.ArbitraryValRef with
1934-
| Some vref when not supportAccessModifiersBeforeGetSet ->
1932+
| Some vref ->
19351933
match pinfo with
19361934
| DifferentGetterAndSetter(getValRef, setValRef) ->
19371935
let getSuffix = if pinfo.IsIndexer then emptyL else WordL.keywordWith ^^ WordL.keywordGet
@@ -1951,26 +1949,6 @@ module TastDefinitionPrinting =
19511949
[ propL ^^ WordL.keywordWith ^^ wordL (tagText "get, set") ]
19521950
else
19531951
[ propL ]
1954-
1955-
| Some vref ->
1956-
let propL = PrintTastMemberOrVals.prettyLayoutOfValOrMemberNoInst denv infoReader vref
1957-
if pinfo.HasGetter && pinfo.HasSetter then
1958-
let rec ``replace 'with'`` layout newLayout =
1959-
match layout with
1960-
| Node(Leaf (text = text), _, _) when text.Text = "with" -> newLayout
1961-
| Node(l, r, i) -> Node(l, ``replace 'with'`` r newLayout , i)
1962-
| Attr(text, attr, l) -> Attr(text, attr, ``replace 'with'`` l newLayout )
1963-
| Leaf _
1964-
| ObjLeaf _ -> layout
1965-
1966-
let getterAccess, setterAccess =
1967-
pinfo.GetterMethod.ArbitraryValRef |> Option.map _.Accessibility |> Option.defaultValue taccessPublic,
1968-
pinfo.SetterMethod.ArbitraryValRef |> Option.map _.Accessibility |> Option.defaultValue taccessPublic
1969-
let getSet =
1970-
WordL.keywordWith ^^ layoutAccessibilityCore denv getterAccess ^^ wordL (tagText "get") ^^ RightL.comma --- layoutAccessibilityCore denv setterAccess ^^ wordL (tagText "set")
1971-
[ ``replace 'with'`` propL getSet ]
1972-
else
1973-
[ propL ]
19741952
| None ->
19751953

19761954
let modifierAndMember =

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ type Exception with
155155
| LibraryUseOnly m
156156
| FieldsFromDifferentTypes(_, _, _, m)
157157
| IndeterminateType m
158+
| InvalidAttributeTargetForLanguageElement(_, _, m)
158159
| TyconBadArgs(_, _, _, m) -> Some m
159160

160161
| FieldNotContained(_, _, _, _, _, arf, _, _) -> Some arf.Range
@@ -353,6 +354,7 @@ type Exception with
353354
| ConstraintSolverNullnessWarningWithTypes _ -> 3261
354355
| ConstraintSolverNullnessWarningWithType _ -> 3261
355356
| ConstraintSolverNullnessWarning _ -> 3261
357+
| InvalidAttributeTargetForLanguageElement _ -> 842
356358
| _ -> 193
357359

358360
type PhasedDiagnostic with
@@ -611,6 +613,9 @@ module OldStyleMessages =
611613
let DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE () =
612614
Message("DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer", "%s%s%s%s")
613615

616+
let InvalidAttributeTargetForLanguageElement1E () = Message("InvalidAttributeTargetForLanguageElement1", "%s%s")
617+
let InvalidAttributeTargetForLanguageElement2E () = Message("InvalidAttributeTargetForLanguageElement2", "")
618+
614619
#if DEBUG
615620
let mutable showParserStackOnParseError = false
616621
#endif
@@ -1932,6 +1937,14 @@ type Exception with
19321937
s2
19331938
)
19341939

1940+
| InvalidAttributeTargetForLanguageElement(elementTargets, allowedTargets, _m) ->
1941+
if Array.isEmpty elementTargets then
1942+
os.AppendString(InvalidAttributeTargetForLanguageElement2E().Format)
1943+
else
1944+
let elementTargets = String.concat ", " elementTargets
1945+
let allowedTargets = allowedTargets |> String.concat ", "
1946+
os.AppendString(InvalidAttributeTargetForLanguageElement1E().Format elementTargets allowedTargets)
1947+
19351948
// Strip TargetInvocationException wrappers
19361949
| :? TargetInvocationException as e when isNotNull e.InnerException -> (!!e.InnerException).Output(os, suggestNames)
19371950

src/Compiler/FSComp.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ tcUnnamedArgumentsDoNotFormPrefix,"The unnamed arguments do not form a prefix of
698698
839,tcUnexpectedConditionInImportedAssembly,"Unexpected condition in imported assembly: failed to decode AttributeUsage attribute"
699699
840,tcUnrecognizedAttributeTarget,"Unrecognized attribute target. Valid attribute targets are 'assembly', 'module', 'type', 'method', 'property', 'return', 'param', 'field', 'event', 'constructor'."
700700
841,tcAttributeIsNotValidForLanguageElementUseDo,"This attribute is not valid for use on this language element. Assembly attributes should be attached to a 'do ()' declaration, if necessary within an F# module."
701-
842,tcAttributeIsNotValidForLanguageElement,"This attribute is not valid for use on this language element"
702701
843,tcOptionalArgumentsCannotBeUsedInCustomAttribute,"Optional arguments cannot be used in custom attributes"
703702
844,tcPropertyCannotBeSet0,"This property cannot be set"
704703
845,tcPropertyOrFieldNotFoundInAttribute,"This property or field was not found on this custom attribute type"

src/Compiler/FSStrings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,4 +1146,10 @@
11461146
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
11471147
<value>keyword 'while!'</value>
11481148
</data>
1149+
<data name="InvalidAttributeTargetForLanguageElement1" xml:space="preserve">
1150+
<value>This attribute cannot be applied to {0}. Valid targets are: {1}</value>
1151+
</data>
1152+
<data name="InvalidAttributeTargetForLanguageElement2" xml:space="preserve">
1153+
<value>This attribute is not valid for use on this language element</value>
1154+
</data>
11491155
</root>

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ type LanguageVersion(versionText) =
236236
LanguageFeature.BetterAnonymousRecordParsing, languageVersion100
237237
LanguageFeature.ScopedNowarn, languageVersion100
238238
LanguageFeature.AllowTypedLetUseAndBang, languageVersion100
239+
LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100
239240

240241
// F# preview (still preview in 10.0)
241242
LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17509
242243
LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work
243-
LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, previewVersion // Stopped printing arguments to indexed properties
244244
]
245245

246246
static let defaultLanguageVersion = LanguageVersion("default")

0 commit comments

Comments
 (0)