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

Prefer extension methods to intrinsic properties when arguments are provided #16032

Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4976d9b
Initial look at issue meant to give priority to extension method if a…
smoothdeveloper Sep 23, 2023
a315a7d
bring it back to the simplest thing that could possibly work, and it …
smoothdeveloper Sep 23, 2023
20c1e7e
Do not break all indexed properties in the world (that is, when there…
smoothdeveloper Sep 23, 2023
82478cb
Implementation: singling out indexer properties and properties with F…
smoothdeveloper Oct 4, 2023
87464c6
Merge branch 'main' into extension-method-priority-when-arguments-pro…
smoothdeveloper Oct 4, 2023
4ab5457
Update LanguageFeatures.fs
smoothdeveloper Oct 5, 2023
3ff50f7
minimize diff
smoothdeveloper Oct 5, 2023
6ca4576
do not break chained calls when there is an extension method with sam…
smoothdeveloper Oct 7, 2023
08a72b5
Merge branch 'main' into extension-method-priority-when-arguments-pro…
smoothdeveloper Oct 7, 2023
189cfe1
fantomas
smoothdeveloper Oct 7, 2023
81cedce
actual chained calls should remain in the sample...
smoothdeveloper Oct 7, 2023
73dfd35
minimize diff
smoothdeveloper Oct 7, 2023
281a2a9
adding test for support of BCL System.Linq.Enumerable.Count()
smoothdeveloper Oct 8, 2023
63e5c91
(minor) formatting.
smoothdeveloper Oct 8, 2023
136a875
fixing partially applied function piped to ignore (https://github.com…
smoothdeveloper Oct 8, 2023
92bf07c
adjust baselines that differ between .net framework and .netcore
smoothdeveloper Oct 8, 2023
30f50b2
checking event handlers aren't affected by the feature
smoothdeveloper Oct 8, 2023
840e20d
Merge branch 'extension-method-priority-when-arguments-provided' of g…
smoothdeveloper Oct 8, 2023
53611ba
separate out Property and Method in DeclarationListInfo.Create, not c…
smoothdeveloper Oct 10, 2023
bdf1c33
handling of static property
smoothdeveloper Oct 15, 2023
17bcc20
Merge branch 'extension-method-priority-when-arguments-provided' of g…
smoothdeveloper Oct 15, 2023
79124e2
Merge branch 'main' into extension-method-priority-when-arguments-pro…
smoothdeveloper Oct 15, 2023
dbdc338
adjust DeclarationListInfo grouping logic to be specific to singling …
smoothdeveloper Oct 22, 2023
5cd091a
Merge branch 'main' into extension-method-priority-when-arguments-pro…
smoothdeveloper Oct 22, 2023
ce1753b
add test checking the latest opened type extension takes precedence
smoothdeveloper Oct 31, 2023
90cd907
Merge branch 'extension-method-priority-when-arguments-provided' of g…
smoothdeveloper Oct 31, 2023
93238bd
Merge commit '7e9f9ade35950603470e7511afb2fd7a291f0e4c' into extensio…
smoothdeveloper Oct 31, 2023
868dd90
minimize diff
smoothdeveloper Oct 31, 2023
6efe48d
minimize diff
smoothdeveloper Oct 31, 2023
6a9791f
Fix test (new error message)
vzarytovskii Nov 1, 2023
b96785b
Merge branch 'main' into extension-method-priority-when-arguments-pro…
smoothdeveloper Nov 7, 2023
61b583f
fix bad merge on baseline file
smoothdeveloper Nov 10, 2023
cbbcb02
better comments explaining the properties that are singled out / can'…
smoothdeveloper Nov 10, 2023
15e2911
revisit DeclarationListInfo.Create to avoid regression where we'd sho…
smoothdeveloper Nov 11, 2023
03821a8
Merge branch 'extension-method-priority-when-arguments-provided' of g…
smoothdeveloper Nov 11, 2023
da5d08c
minimize diff
smoothdeveloper Nov 11, 2023
33c6a9a
try to make fantomas happy, despite I don't see the difference
smoothdeveloper Nov 11, 2023
54c0cb9
minimize diff
smoothdeveloper Nov 11, 2023
4d49ba5
formatting & add a comment explaining usage of `createSublists`
smoothdeveloper Nov 11, 2023
6e493c8
Merge commit 'd441308a78724ea47584027af697789c8d2e1a94' into extensio…
smoothdeveloper Nov 11, 2023
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
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let (|JoinRelation|_|) cenv env (expr: SynExpr) =

let isOpName opName vref s =
(s = opName) &&
match ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.eNameResEnv TypeNameResolutionInfo.Default [ident(opName, m)] with
match ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.eNameResEnv TypeNameResolutionInfo.Default [ident(opName, m)] None with
| Result (_, Item.Value vref2, []) -> valRefEq cenv.g vref vref2
| _ -> false

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ module TcExceptionDeclarations =
match reprIdOpt with
| Some longId ->
let resolution =
ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.NameEnv TypeNameResolutionInfo.Default longId
ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.NameEnv TypeNameResolutionInfo.Default longId None
|> ForceRaise
match resolution with
| _, Item.ExnCase exnc, [] ->
Expand Down
19 changes: 14 additions & 5 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,13 @@ type DelayedItem =
/// Represents the valueExpr in "item <- valueExpr", also "item.[indexerArgs] <- valueExpr" etc.
| DelayedSet of SynExpr * range

module DelayedItem =
let maybeAppliedArgForPreferExtensionOverProperty delayed =
match delayed with
| [] -> None
| DelayedItem.DelayedApp(argExpr=argExpr) :: _ -> Some argExpr
| _ -> None

let MakeDelayedSet(e: SynExpr, m) =
// We have longId <- e. Wrap 'e' in another pair of parentheses to ensure it's never interpreted as
// a named argument, e.g. for "el.Checked <- (el = el2)"
Expand Down Expand Up @@ -8093,7 +8100,7 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) =
// However we don't commit for a type names - nameof allows 'naked' type names and thus all type name
// resolutions are checked separately in the next step.
let typeNameResInfo = GetLongIdentTypeNameInfo delayed
let nameResolutionResult = ResolveLongIdentAsExprAndComputeRange cenv.tcSink cenv.nameResolver (rangeOfLid longId) ad env.eNameResEnv typeNameResInfo longId
let nameResolutionResult = ResolveLongIdentAsExprAndComputeRange cenv.tcSink cenv.nameResolver (rangeOfLid longId) ad env.eNameResEnv typeNameResInfo longId None
let resolvesAsExpr =
match nameResolutionResult with
| Result (_, item, _, _, _ as res)
Expand Down Expand Up @@ -8304,7 +8311,8 @@ and TcLongIdentThen (cenv: cenv) (overallTy: OverallTy) env tpenv (SynLongIdent(
let ad = env.eAccessRights
let typeNameResInfo = GetLongIdentTypeNameInfo delayed
let nameResolutionResult =
ResolveLongIdentAsExprAndComputeRange cenv.tcSink cenv.nameResolver (rangeOfLid longId) ad env.eNameResEnv typeNameResInfo longId
let maybeAppliedArgExpr = DelayedItem.maybeAppliedArgForPreferExtensionOverProperty delayed
ResolveLongIdentAsExprAndComputeRange cenv.tcSink cenv.nameResolver (rangeOfLid longId) ad env.eNameResEnv typeNameResInfo longId maybeAppliedArgExpr
|> ForceRaise
TcItemThen cenv overallTy env tpenv nameResolutionResult None delayed

Expand Down Expand Up @@ -8556,7 +8564,7 @@ and TcTypeItemThen (cenv: cenv) overallTy env nm ty tpenv mItem tinstEnclosing d
let item = Item.Types(nm, [ty])
CallNameResolutionSink cenv.tcSink (mExprAndTypeArgs, env.NameEnv, item, emptyTyparInst, ItemOccurence.Use, env.eAccessRights)
let typeNameResInfo = GetLongIdentTypeNameInfo otherDelayed
let item, mItem, rest, afterResolution = ResolveExprDotLongIdentAndComputeRange cenv.tcSink cenv.nameResolver (unionRanges mExprAndTypeArgs mLongId) ad env.eNameResEnv ty longId typeNameResInfo IgnoreOverrides true
let item, mItem, rest, afterResolution = ResolveExprDotLongIdentAndComputeRange cenv.tcSink cenv.nameResolver (unionRanges mExprAndTypeArgs mLongId) ad env.eNameResEnv ty longId typeNameResInfo IgnoreOverrides true None
TcItemThen cenv overallTy env tpenv ((argsOfAppTy g ty), item, mItem, rest, afterResolution) None otherDelayed

| DelayedTypeApp(tyargs, _mTypeArgs, mExprAndTypeArgs) :: _delayed' ->
Expand Down Expand Up @@ -9120,8 +9128,9 @@ and TcLookupThen cenv overallTy env tpenv mObjExpr objExpr objExprTy longId dela
// Canonicalize inference problem prior to '.' lookup on variable types
if isTyparTy g objExprTy then
CanonicalizePartialInferenceProblem cenv.css env.DisplayEnv mExprAndLongId (freeInTypeLeftToRight g false objExprTy)

let item, mItem, rest, afterResolution = ResolveExprDotLongIdentAndComputeRange cenv.tcSink cenv.nameResolver mExprAndLongId ad env.NameEnv objExprTy longId TypeNameResolutionInfo.Default findFlag false

let maybeAppliedArgExpr = DelayedItem.maybeAppliedArgForPreferExtensionOverProperty delayed
let item, mItem, rest, afterResolution = ResolveExprDotLongIdentAndComputeRange cenv.tcSink cenv.nameResolver mExprAndLongId ad env.NameEnv objExprTy longId TypeNameResolutionInfo.Default findFlag false maybeAppliedArgExpr
TcLookupItemThen cenv overallTy env tpenv mObjExpr objExpr objExprTy delayed item mItem rest afterResolution

and TcLookupItemThen cenv overallTy env tpenv mObjExpr objExpr objExprTy delayed item mItem rest afterResolution =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ and IsNameOf (cenv: cenv) (env: TcEnv) ad m (id: Ident) =
let g = cenv.g
id.idText = "nameof" &&
try
match ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.NameEnv TypeNameResolutionInfo.Default [id] with
match ResolveExprLongIdent cenv.tcSink cenv.nameResolver m ad env.NameEnv TypeNameResolutionInfo.Default [id] None with
| Result (_, Item.Value vref, _) -> valRefEq g vref g.nameof_vref
| _ -> false
with _ -> false
Expand Down
Loading
Loading