Skip to content

Commit 3724334

Browse files
alfonsogarciacaroncave
authored andcommitted
Don't lose attributes of method parameters (#12)
Temporary fix, remove when upstream dotnet#13786 is fixed.
1 parent 43c1bfd commit 3724334

10 files changed

+24
-24
lines changed

src/Compiler/Checking/Expressions/CheckComputationExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ let tryGetArgAttribsForCustomOperator ceenv (nm: Ident) =
460460
_joinConditionWord,
461461
methInfo) ->
462462
match methInfo.GetParamAttribs(ceenv.cenv.amap, ceenv.mWhole) with
463-
| [ curriedArgInfo ] -> Some curriedArgInfo // one for the actual argument group
463+
| [ curriedArgInfo ] -> Some (List.map fst curriedArgInfo) // one for the actual argument group
464464
| _ -> None)
465465
|> Some
466466
| _ -> None

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,7 +4188,7 @@ and TcPseudoMemberSpec cenv newOk env synTypes tpenv synMemberSig m =
41884188
let logicalCompiledName = ComputeLogicalName id memberFlags
41894189
for argInfos in curriedArgInfos do
41904190
for argInfo in argInfos do
4191-
let info = CrackParamAttribsInfo g argInfo
4191+
let info, _ = CrackParamAttribsInfo g argInfo
41924192
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
41934193
if isParamArrayArg || isInArg || isOutArg || optArgInfo.IsOptional || callerInfo <> CallerInfo.NoCallerInfo || reflArgInfo <> ReflectedArgInfo.None then
41944194
if g.langVersion.SupportsFeature(LanguageFeature.InterfacesWithAbstractStaticMembers) then
@@ -9779,6 +9779,7 @@ and GenerateMatchingSimpleArgumentTypes (cenv: cenv) (calledMeth: MethInfo) mIte
97799779
let g = cenv.g
97809780
let curriedMethodArgAttribs = calledMeth.GetParamAttribs(cenv.amap, mItem)
97819781
curriedMethodArgAttribs
9782+
|> List.map (List.map fst)
97829783
|> List.map (List.filter isSimpleFormalArg >> NewInferenceTypes g)
97839784

97849785
and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMeth: MethInfo) mMethExpr mItem =
@@ -9832,7 +9833,7 @@ and TcMethodApplication_SplitSynArguments
98329833
let singleMethodCurriedArgs =
98339834
match candidates with
98349835
| [calledMeth] when List.forall isNil namedCurriedCallerArgs ->
9835-
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem)
9836+
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem) |> List.map (List.map fst)
98369837
match curriedCalledArgs with
98379838
| [arg :: _] when isSimpleFormalArg arg -> Some(curriedCalledArgs)
98389839
| _ -> None
@@ -10077,7 +10078,7 @@ and TcAdhocChecksOnLibraryMethods (cenv: cenv) (env: TcEnv) isInstance (finalCal
1007710078
if HasHeadType g g.tcref_System_Collections_Generic_Dictionary finalCalledMethInfo.ApparentEnclosingType &&
1007810079
finalCalledMethInfo.IsConstructor &&
1007910080
not (finalCalledMethInfo.GetParamDatas(cenv.amap, mItem, finalCalledMeth.CalledTyArgs)
10080-
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty)) ->
10081+
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty), _) ->
1008110082
HasHeadType g g.tcref_System_Collections_Generic_IEqualityComparer ty)) then
1008210083

1008310084
match argsOfAppTy g finalCalledMethInfo.ApparentEnclosingType with

src/Compiler/Checking/MethodCalls.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ type CalledMethArgSet<'T> =
471471
let MakeCalledArgs amap m (minfo: MethInfo) minst =
472472
// Mark up the arguments with their position, so we can sort them back into order later
473473
let paramDatas = minfo.GetParamDatas(amap, m, minst)
474-
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy)) ->
474+
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy), _) ->
475475
{ Position=(i,j)
476476
IsParamArray=isParamArrayArg
477477
OptArgInfo=optArgInfo

src/Compiler/Checking/NicePrint.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ module InfoMemberPrinting =
16421642
let layout = layoutXmlDocOfMethInfo denv infoReader minfo layout
16431643

16441644
let paramsL =
1645-
let paramDatas = minfo.GetParamDatas(amap, m, minst)
1645+
let paramDatas = minfo.GetParamDatas(amap, m, minst) |> List.map (List.map fst)
16461646
if List.forall isNil paramDatas then
16471647
WordL.structUnit
16481648
else
@@ -1704,6 +1704,7 @@ module InfoMemberPrinting =
17041704
| _ ->
17051705
layout,
17061706
minfo.GetParamDatas (amap, m, minst)
1707+
|> List.map (List.map fst)
17071708
|> List.concat
17081709
|> List.map (layoutParamData denv)
17091710

src/Compiler/Checking/PostInferenceChecks.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,13 +2393,13 @@ let CheckEntityDefn cenv env (tycon: Entity) =
23932393

23942394
if numCurriedArgSets > 1 &&
23952395
(minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
2396-
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty)) ->
2396+
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty), _) ->
23972397
isParamArrayArg || isOutArg || reflArgInfo.AutoQuote || optArgInfo.IsOptional || callerInfo <> NoCallerInfo || isByrefLikeTy g m ty)) then
23982398
errorR(Error(FSComp.SR.chkCurriedMethodsCantHaveOutParams(), m))
23992399

24002400
if numCurriedArgSets = 1 then
24012401
minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
2402-
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty)) ->
2402+
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty), _) ->
24032403
ignore isInArg
24042404
match (optArgInfo, callerInfo) with
24052405
| _, NoCallerInfo -> ()

src/Compiler/Checking/infos.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ let CrackParamAttribsInfo g (ty: TType, argInfo: ArgReprInfo) =
337337
| ValueSome optTy when typeEquiv g g.int32_ty optTy -> CallerFilePath
338338
| _ -> CallerLineNumber
339339

340-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)
340+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), argInfo.Attribs
341341

342342
#if !NO_TYPEPROVIDERS
343343

@@ -1293,7 +1293,7 @@ type MethInfo =
12931293
if p.Type.TypeRef.FullName = "System.Int32" then CallerFilePath
12941294
else CallerLineNumber
12951295

1296-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo) ] ]
1296+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), [] ] ]
12971297

12981298
| FSMeth(g, _, vref, _) ->
12991299
GetArgInfosOfMember x.IsCSharpStyleExtensionMember g vref
@@ -1315,7 +1315,7 @@ type MethInfo =
13151315
| None -> ReflectedArgInfo.None
13161316
let isOutArg = p.PUntaint((fun p -> p.IsOut && not p.IsIn), m)
13171317
let isInArg = p.PUntaint((fun p -> p.IsIn && not p.IsOut), m)
1318-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo)] ]
1318+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo), [] ] ]
13191319
#endif
13201320

13211321
/// Get the signature of an abstract method slot.
@@ -1426,13 +1426,13 @@ type MethInfo =
14261426
#endif
14271427

14281428
let paramAttribs = x.GetParamAttribs(amap, m)
1429-
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun info (ParamNameAndType(nmOpt, pty)) ->
1430-
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
1431-
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty)))
1429+
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun (info, attribs) (ParamNameAndType(nmOpt, pty)) ->
1430+
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
1431+
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty), attribs))
14321432

14331433
/// Get the ParamData objects for the parameters of a MethInfo
14341434
member x.HasParamArrayArg(amap, m, minst) =
1435-
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _)) -> isParamArrayArg)
1435+
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _), _) -> isParamArrayArg)
14361436

14371437
/// Select all the type parameters of the declaring type of a method.
14381438
///

src/Compiler/Checking/infos.fsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ type ParamAttribs =
146146
callerInfo: CallerInfo *
147147
reflArgInfo: ReflectedArgInfo
148148

149-
val CrackParamAttribsInfo: TcGlobals -> ty: TType * argInfo: ArgReprInfo -> ParamAttribs
149+
val CrackParamAttribsInfo: TcGlobals -> ty: TType * argInfo: ArgReprInfo -> ParamAttribs * Attribs
150150

151151
/// Describes an F# use of an IL type, including the type instantiation associated with the type at a particular usage point.
152152
[<NoComparison; NoEquality>]
@@ -524,10 +524,10 @@ type MethInfo =
524524
member GetCustomAttrs: unit -> ILAttributes
525525

526526
/// Get the parameter attributes of a method info, which get combined with the parameter names and types
527-
member GetParamAttribs: amap: ImportMap * m: range -> ParamAttribs list list
527+
member GetParamAttribs: amap: ImportMap * m: range -> (ParamAttribs * Attribs) list list
528528

529529
/// Get the ParamData objects for the parameters of a MethInfo
530-
member GetParamDatas: amap: ImportMap * m: range * minst: TType list -> ParamData list list
530+
member GetParamDatas: amap: ImportMap * m: range * minst: TType list -> (ParamData * Attribs) list list
531531

532532
/// Get the parameter names of a MethInfo
533533
member GetParamNames: unit -> string option list list

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ type internal TypeCheckInfo
654654
match meth.GetParamDatas(amap, m, meth.FormalMethodInst) with
655655
| x :: _ ->
656656
x
657-
|> List.choose (fun (ParamData(_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty)) ->
657+
|> List.choose (fun (ParamData(_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty), _) ->
658658
match name with
659659
| Some id -> Some(Item.OtherName(Some id, ty, None, Some(ArgumentContainer.Method meth), id.idRange))
660660
| None -> None)

src/Compiler/Service/ServiceDeclarationLists.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ module internal DescriptionListsImpl =
799799

800800
| Item.CtorGroup(_, minfo :: _)
801801
| Item.MethodGroup(_, minfo :: _, _) ->
802-
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head
802+
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head |> List.map fst
803803
let retTy = minfo.GetFSharpReturnType(amap, m, minfo.FormalMethodInst)
804804
let _prettyTyparInst, prettyParams, prettyRetTyL, _prettyConstraintsL = PrettyParamsOfParamDatas g denv item.TyparInstantiation paramDatas retTy
805805
// FUTURE: prettyTyparInst is the pretty version of the known instantiations of type parameters in the output. It could be returned

src/Compiler/Symbols/Symbols.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,10 +2120,8 @@ type FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
21202120
| M m | C m ->
21212121
[ for argTys in m.GetParamDatas(cenv.amap, range0, m.FormalMethodInst) do
21222122
yield
2123-
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty) in argTys do
2124-
// INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
2125-
// either .NET or F# parameters
2126-
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs=[]; OtherRange=None }
2123+
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty), attribs in argTys do
2124+
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs=attribs; OtherRange=None }
21272125
let m =
21282126
match nmOpt with
21292127
| Some v -> v.idRange

0 commit comments

Comments
 (0)