Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1799aaf
make attribute targets mismatches a warning and not an error.
edgarfgp Apr 23, 2025
55507e9
release notes
edgarfgp Apr 23, 2025
1738018
update tests
edgarfgp Apr 23, 2025
65f5bb6
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 24, 2025
0c97b9d
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 27, 2025
6f2b706
update baselines
edgarfgp Apr 29, 2025
e8f1bb0
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 29, 2025
75d8f5e
Update baselines
edgarfgp Apr 29, 2025
4f2e97e
Merge branch 'fix-attr-targets' of github.com:edgarfgp/fsharp into fi…
edgarfgp Apr 29, 2025
63be5d5
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 30, 2025
4248f2a
Move attribute form logic to an AP
edgarfgp Apr 30, 2025
cc96217
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e270b88
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e0cc65a
Merge branch 'main' into fix-attr-targets
edgarfgp May 2, 2025
1e29d58
Merge branch 'main' into fix-attr-targets
edgarfgp May 5, 2025
1470bf9
Merge branch 'main' into fix-attr-targets
edgarfgp May 6, 2025
8988215
Merge branch 'main' into fix-attr-targets
edgarfgp May 7, 2025
74712e8
Merge branch 'main' into fix-attr-targets
edgarfgp May 12, 2025
967c4a9
Merge branch 'main' of github.com:edgarfgp/fsharp
edgarfgp May 13, 2025
a30cef4
Merge branch 'dotnet:main' into main
edgarfgp May 22, 2025
5fa0480
Merge branch 'dotnet:main' into main
edgarfgp May 24, 2025
15e3d34
Merge branch 'dotnet:main' into main
edgarfgp May 29, 2025
049472b
Better error message for attribute targets
edgarfgp May 30, 2025
f643b60
Update src/Compiler/Checking/Expressions/CheckExpressions.fs
edgarfgp May 31, 2025
e8cdb61
Merge branch 'main' into attr-targets-better-error-message
edgarfgp May 31, 2025
61483ce
use attrTgt instead of directedTargets
edgarfgp May 31, 2025
81089ce
update attrTgt
edgarfgp May 31, 2025
f207e37
update tests
edgarfgp May 31, 2025
7b1386c
Add InvalidAttributeTargetForLanguageElement2 as fallback
edgarfgp May 31, 2025
0c55b19
Update more tests
edgarfgp May 31, 2025
a309081
release notes
edgarfgp May 31, 2025
ea02da5
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jun 2, 2025
c83a358
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jun 3, 2025
5119d61
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jun 5, 2025
296a438
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jun 6, 2025
75fed14
PR feedback
edgarfgp Jun 9, 2025
0097493
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jun 19, 2025
e115b57
update tests
edgarfgp Jun 19, 2025
2272c0c
Merge branch 'attr-targets-better-error-message' of github.com:edgarf…
edgarfgp Jun 19, 2025
42496c3
update tests
edgarfgp Jun 19, 2025
e6ddead
Merge branch 'main' into attr-targets-better-error-message
edgarfgp Jul 8, 2025
573461c
update tests
edgarfgp Jul 9, 2025
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
* Fix parsing errors using anonymous records and code quotations ([PR #18603](https://github.com/dotnet/fsharp/pull/18603))
* Better error message for attribute targets. ([PR #18641](https://github.com/dotnet/fsharp/pull/18641))
* Fixed: Allow `return`, `return!`, `yield`, `yield!` type annotations without parentheses ([PR #18533](https://github.com/dotnet/fsharp/pull/18533))
* Allow `let!` and `use!` type annotations without requiring parentheses ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))
* Fix find all references for F# exceptions ([PR #18565](https://github.com/dotnet/fsharp/pull/18565))
Expand Down
26 changes: 25 additions & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ exception StandardOperatorRedefinitionWarning of string * range

exception InvalidInternalsVisibleToAssemblyName of badName: string * fileName: string option

exception InvalidAttributeTargetForLanguageElement of elementTargets: string array * allowedTargets: string array * range: range

//----------------------------------------------------------------------------------------------
// Helpers for determining if/what specifiers a string has.
// Used to decide if interpolated string can be lowered to a concat call.
Expand Down Expand Up @@ -11356,7 +11358,29 @@ and CheckAttributeUsage (g: TcGlobals) (mAttr: range) (tcref: TyconRef) (attrTgt
if (directedTargets = AttributeTargets.Assembly || directedTargets = AttributeTargets.Module) then
errorR(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElementUseDo(), mAttr))
else
warning(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElement(), mAttr))
let attributeTargetsToString (targets: int) =
[|
if targets &&& int AttributeTargets.Assembly <> 0 then "assembly"
if targets &&& int AttributeTargets.Module <> 0 then "module"
if targets &&& int AttributeTargets.Class <> 0 then "class"
if targets &&& int AttributeTargets.Struct <> 0 then "struct"
if targets &&& int AttributeTargets.Enum <> 0 then "enum"
if targets &&& int AttributeTargets.Constructor <> 0 then "constructor"
if targets &&& int AttributeTargets.Method <> 0 then "method"
if targets &&& int AttributeTargets.Property <> 0 then "property"
if targets &&& int AttributeTargets.Field <> 0 then "field"
if targets &&& int AttributeTargets.Event <> 0 then "event"
if targets &&& int AttributeTargets.Interface <> 0 then "interface"
if targets &&& int AttributeTargets.Parameter <> 0 then "parameter"
if targets &&& int AttributeTargets.Delegate <> 0 then "delegate"
if targets &&& int AttributeTargets.ReturnValue <> 0 then "return value"
if targets &&& int AttributeTargets.GenericParameter <> 0 then "type parameter"
|]

let elementTargets = attributeTargetsToString (int attrTgt)
let allowedTargets = attributeTargetsToString validOn

warning(InvalidAttributeTargetForLanguageElement(elementTargets, allowedTargets, mAttr))

constrainedTargets

Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/Checking/Expressions/CheckExpressions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ exception StandardOperatorRedefinitionWarning of string * range

exception InvalidInternalsVisibleToAssemblyName of badName: string * fileName: string option

exception InvalidAttributeTargetForLanguageElement of
elementTargets: string array *
allowedTargets: string array *
range: range

val TcFieldInit: range -> ILFieldInit -> Const

/// Indicates whether a syntactic type is allowed to include new type variables
Expand Down
13 changes: 13 additions & 0 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Exception with
| LibraryUseOnly m
| FieldsFromDifferentTypes(_, _, _, m)
| IndeterminateType m
| InvalidAttributeTargetForLanguageElement(_, _, m)
| TyconBadArgs(_, _, _, m) -> Some m

| FieldNotContained(_, _, _, _, _, arf, _, _) -> Some arf.Range
Expand Down Expand Up @@ -353,6 +354,7 @@ type Exception with
| ConstraintSolverNullnessWarningWithTypes _ -> 3261
| ConstraintSolverNullnessWarningWithType _ -> 3261
| ConstraintSolverNullnessWarning _ -> 3261
| InvalidAttributeTargetForLanguageElement _ -> 842
| _ -> 193

type PhasedDiagnostic with
Expand Down Expand Up @@ -611,6 +613,9 @@ module OldStyleMessages =
let DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE () =
Message("DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer", "%s%s%s%s")

let InvalidAttributeTargetForLanguageElement1E () = Message("InvalidAttributeTargetForLanguageElement1", "%s%s")
let InvalidAttributeTargetForLanguageElement2E () = Message("InvalidAttributeTargetForLanguageElement2", "")

#if DEBUG
let mutable showParserStackOnParseError = false
#endif
Expand Down Expand Up @@ -1932,6 +1937,14 @@ type Exception with
s2
)

| InvalidAttributeTargetForLanguageElement(elementTargets, allowedTargets, _m) ->
if Array.isEmpty elementTargets then
os.AppendString(InvalidAttributeTargetForLanguageElement2E().Format)
else
let elementTargets = String.concat ", " elementTargets
let allowedTargets = allowedTargets |> String.concat ", "
os.AppendString(InvalidAttributeTargetForLanguageElement1E().Format elementTargets allowedTargets)

// Strip TargetInvocationException wrappers
| :? TargetInvocationException as e when isNotNull e.InnerException -> (!!e.InnerException).Output(os, suggestNames)

Expand Down
1 change: 0 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ tcUnnamedArgumentsDoNotFormPrefix,"The unnamed arguments do not form a prefix of
839,tcUnexpectedConditionInImportedAssembly,"Unexpected condition in imported assembly: failed to decode AttributeUsage attribute"
840,tcUnrecognizedAttributeTarget,"Unrecognized attribute target. Valid attribute targets are 'assembly', 'module', 'type', 'method', 'property', 'return', 'param', 'field', 'event', 'constructor'."
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."
842,tcAttributeIsNotValidForLanguageElement,"This attribute is not valid for use on this language element"
843,tcOptionalArgumentsCannotBeUsedInCustomAttribute,"Optional arguments cannot be used in custom attributes"
844,tcPropertyCannotBeSet0,"This property cannot be set"
845,tcPropertyOrFieldNotFoundInAttribute,"This property or field was not found on this custom attribute type"
Expand Down
6 changes: 6 additions & 0 deletions src/Compiler/FSStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1146,4 +1146,10 @@
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
<value>keyword 'while!'</value>
</data>
<data name="InvalidAttributeTargetForLanguageElement1" xml:space="preserve">
<value>This attribute cannot be applied to {0}. Valid targets are: {1}</value>
</data>
<data name="InvalidAttributeTargetForLanguageElement2" xml:space="preserve">
<value>This attribute is not valid for use on this language element</value>
</data>
</root>
5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 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.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

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

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

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

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

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

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

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

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

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

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.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/FSStrings.cs.xlf

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

Loading
Loading