Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete attribute is ignored in constructor property assignment. #16900

Merged
merged 24 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
925f033
Obsolete attribute is ignored in constructor property assignment
edgarfgp Mar 11, 2024
a5f8032
Raise an warning when Obsolete attribute is used in constructor prope…
edgarfgp Mar 11, 2024
4558fff
release notes
edgarfgp Mar 21, 2024
35997f9
Merge branch 'main' into fix-11868
edgarfgp Mar 21, 2024
ed89056
Merge branch 'main' into fix-11868
edgarfgp Mar 22, 2024
1ae43a5
Merge branch 'main' into fix-11868
edgarfgp Mar 25, 2024
aa1c61e
Use a more accuarate range
edgarfgp Mar 25, 2024
9f51d0e
Merge branch 'fix-11868' of https://github.com/edgarfgp/fsharp into f…
edgarfgp Mar 25, 2024
93a0f1a
GetImmediateIntrinsicPropInfosOfType
edgarfgp Mar 25, 2024
ea5e736
more tests
edgarfgp Mar 25, 2024
b831f7f
Merge branch 'main' into fix-11868
edgarfgp Mar 25, 2024
7655d24
more tests
edgarfgp Mar 26, 2024
f33f922
Update logic to check one case at the time
edgarfgp Mar 26, 2024
1aa1188
Merge branch 'fix-11868' of https://github.com/edgarfgp/fsharp into f…
edgarfgp Mar 26, 2024
809ea70
getConstructorArgs
edgarfgp Mar 26, 2024
201470a
FIx PR comments
edgarfgp Mar 26, 2024
c63aa76
Merge branch 'main' into fix-11868
edgarfgp Mar 26, 2024
2d24709
Merge branch 'main' into fix-11868
edgarfgp Mar 26, 2024
a112243
Merge branch 'main' into fix-11868
edgarfgp Mar 27, 2024
af745e0
Simplify check
edgarfgp Mar 28, 2024
299a188
even more simpler
edgarfgp Mar 28, 2024
ffadcf8
Merge branch 'main' into fix-11868
edgarfgp Mar 29, 2024
a462bd9
Merge branch 'main' into fix-11868
edgarfgp Apr 2, 2024
ed1196c
Merge branch 'main' into fix-11868
edgarfgp Apr 2, 2024
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
23 changes: 13 additions & 10 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6655,24 +6655,27 @@ and TcCtorCall isNaked cenv env tpenv (overallTy: OverallTy) objTy mObjTyOpt ite
| SynExpr.Paren(expr = SynExpr.App(funcExpr = expr)) ->
getConstructorArgs expr
| SynExpr.Paren(expr = SynExpr.Tuple(exprs = synExprs)) ->
synExprs
|> List.collect getConstructorArgs
synExprs |> List.collect getConstructorArgs
| SynExpr.App(funcExpr = expr1; argExpr = expr2) ->
getConstructorArgs expr1 @ getConstructorArgs expr2
| SynExpr.Ident(id) -> [id]
| SynExpr.Ident(id) -> [ id ]
| _ -> []

match item, args with
| Item.CtorGroup(methodName, minfos), exprArgs ->
| Item.CtorGroup(methodName, minfos), argExprs ->
let meths = List.map (fun minfo -> minfo, None) minfos
if isNaked && TypeFeasiblySubsumesType 0 g cenv.amap mWholeCall g.system_IDisposable_ty NoCoerce objTy then
warning(Error(FSComp.SR.tcIDisposableTypeShouldUseNew(), mWholeCall))
let valRefs = minfos |> List.collect (fun minfo -> minfo.ApparentEnclosingTyconRef.MembersOfFSharpTyconSorted)
let ctorArgs = exprArgs |> List.collect getConstructorArgs

if not ctorArgs.IsEmpty then
for valRef in valRefs do
CheckValAttributes g valRef mItem |> CommitOperationResult

let valRefs =
minfos
|> List.collect (fun minfo-> minfo.ApparentEnclosingTyconRef.MembersOfFSharpTyconSorted)
|> List.filter (fun v -> CheckFSharpAttributesForObsolete g v.Attribs)
for vref in valRefs do
let ctorArgs = argExprs |> List.collect getConstructorArgs
for arg in ctorArgs do
if arg.idText = vref.DisplayName then
CheckValAttributes g vref arg.idRange |> CommitOperationResult

// Check the type is not abstract
// skip this check if this ctor call is either 'inherit(...)' or call is located within constructor shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,9 @@ let f (x: IFirst) = x.F()
(Error 101, Line 13, Col 11, Line 13, Col 17, "This construct is deprecated. Use G instead")
(Error 72, Line 13, Col 21, Line 13, Col 24, "Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.")
]

[<Fact>]
let ``Obsolete attribute warning is taken into account in a constructor property assigment`` () =
let ``Obsolete attribute warning is taken into account in a constructor property assignment`` () =
Fsx """
open System
type JsonSerializerOptions() =
Expand All @@ -1274,8 +1274,33 @@ type JsonSerializerOptions() =
member val UseCustomOptions = false with get, set

let options = JsonSerializerOptions(DefaultOptions = true, UseCustomOptions = false)
let options2 = JsonSerializerOptions(DefaultOptions = true, DefaultOptions = false)
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Warning 44, Line 9, Col 37, Line 9, Col 51, "This construct is deprecated. This is bad")
(Warning 44, Line 10, Col 38, Line 10, Col 52, "This construct is deprecated. This is bad")
(Warning 44, Line 10, Col 61, Line 10, Col 75, "This construct is deprecated. This is bad")
(Error 364, Line 10, Col 16, Line 10, Col 84, "The named argument 'DefaultOptions' has been assigned more than one value")
]

[<Fact>]
let ``Obsolete attribute error is taken into account in a constructor property assignment`` () =
Fsx """
open System
type JsonSerializerOptions() =
[<Obsolete("This is bad", true)>]
member val DefaultOptions = false with get, set

member val UseCustomOptions = false with get, set

let options = JsonSerializerOptions(DefaultOptions = true, UseCustomOptions = false)
let options2 = JsonSerializerOptions(DefaultOptions = true, DefaultOptions = false)
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
]
(Error 101, Line 9, Col 37, Line 9, Col 51, "This construct is deprecated. This is bad")
(Error 101, Line 10, Col 38, Line 10, Col 52, "This construct is deprecated. This is bad")
]
Loading