Skip to content

Commit ded9225

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

10 files changed

+23
-24
lines changed

src/Compiler/Checking/CheckComputationExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
435435
argInfos
436436
|> List.map (fun (_nm, __maintainsVarSpaceUsingBind, _maintainsVarSpace, _allowInto, _isLikeZip, _isLikeJoin, _isLikeGroupJoin, _joinConditionWord, methInfo) ->
437437
match methInfo.GetParamAttribs(cenv.amap, mWhole) with
438-
| [curriedArgInfo] -> Some curriedArgInfo // one for the actual argument group
438+
| [curriedArgInfo] -> Some (List.map fst curriedArgInfo) // one for the actual argument group
439439
| _ -> None)
440440
|> Some
441441
| _ -> None

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,7 +4049,7 @@ and TcPseudoMemberSpec cenv newOk env synTypes tpenv synMemberSig m =
40494049
let logicalCompiledName = ComputeLogicalName id memberFlags
40504050
for argInfos in curriedArgInfos do
40514051
for argInfo in argInfos do
4052-
let info = CrackParamAttribsInfo g argInfo
4052+
let info, _ = CrackParamAttribsInfo g argInfo
40534053
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
40544054
if isParamArrayArg || isInArg || isOutArg || optArgInfo.IsOptional || callerInfo <> CallerInfo.NoCallerInfo || reflArgInfo <> ReflectedArgInfo.None then
40554055
if g.langVersion.SupportsFeature(LanguageFeature.InterfacesWithAbstractStaticMembers) then
@@ -9264,6 +9264,7 @@ and GenerateMatchingSimpleArgumentTypes (cenv: cenv) (calledMeth: MethInfo) mIte
92649264
let g = cenv.g
92659265
let curriedMethodArgAttribs = calledMeth.GetParamAttribs(cenv.amap, mItem)
92669266
curriedMethodArgAttribs
9267+
|> List.map (List.map fst)
92679268
|> List.map (List.filter isSimpleFormalArg >> NewInferenceTypes g)
92689269

92699270
and UnifyMatchingSimpleArgumentTypes (cenv: cenv) (env: TcEnv) exprTy (calledMeth: MethInfo) mMethExpr mItem =
@@ -9317,7 +9318,7 @@ and TcMethodApplication_SplitSynArguments
93179318
let singleMethodCurriedArgs =
93189319
match candidates with
93199320
| [calledMeth] when List.forall isNil namedCurriedCallerArgs ->
9320-
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem)
9321+
let curriedCalledArgs = calledMeth.GetParamAttribs(cenv.amap, mItem) |> List.map (List.map fst)
93219322
match curriedCalledArgs with
93229323
| [arg :: _] when isSimpleFormalArg arg -> Some(curriedCalledArgs)
93239324
| _ -> None
@@ -9552,7 +9553,7 @@ and TcAdhocChecksOnLibraryMethods (cenv: cenv) (env: TcEnv) isInstance (finalCal
95529553
if HasHeadType g g.tcref_System_Collections_Generic_Dictionary finalCalledMethInfo.ApparentEnclosingType &&
95539554
finalCalledMethInfo.IsConstructor &&
95549555
not (finalCalledMethInfo.GetParamDatas(cenv.amap, mItem, finalCalledMeth.CalledTyArgs)
9555-
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty)) ->
9556+
|> List.existsSquared (fun (ParamData(_, _, _, _, _, _, _, ty), _) ->
95569557
HasHeadType g g.tcref_System_Collections_Generic_IEqualityComparer ty)) then
95579558

95589559
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
@@ -478,7 +478,7 @@ type CalledMethArgSet<'T> =
478478
let MakeCalledArgs amap m (minfo: MethInfo) minst =
479479
// Mark up the arguments with their position, so we can sort them back into order later
480480
let paramDatas = minfo.GetParamDatas(amap, m, minst)
481-
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy)) ->
481+
paramDatas |> List.mapiSquared (fun i j (ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfoFlags, nmOpt, reflArgInfo, calledArgTy), _) ->
482482
{ Position=(i,j)
483483
IsParamArray=isParamArrayArg
484484
OptArgInfo=optArgInfo

src/Compiler/Checking/NicePrint.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ module InfoMemberPrinting =
14701470
let layout = layoutXmlDocOfMethInfo denv infoReader minfo layout
14711471

14721472
let paramsL =
1473-
let paramDatas = minfo.GetParamDatas(amap, m, minst)
1473+
let paramDatas = minfo.GetParamDatas(amap, m, minst) |> List.map (List.map fst)
14741474
if List.forall isNil paramDatas then
14751475
WordL.structUnit
14761476
else
@@ -1513,7 +1513,7 @@ module InfoMemberPrinting =
15131513
PrintTypes.layoutTyparDecls denv idL true minfo.FormalMethodTypars ^^
15141514
SepL.leftParen
15151515

1516-
let paramDatas = minfo.GetParamDatas (amap, m, minst)
1516+
let paramDatas = minfo.GetParamDatas (amap, m, minst) |> List.map (List.map fst)
15171517
let layout = layout ^^ sepListL RightL.comma ((List.concat >> List.map (layoutParamData denv)) paramDatas)
15181518
layout ^^ RightL.rightParen ^^ WordL.colon ^^ PrintTypes.layoutType denv retTy
15191519

src/Compiler/Checking/PostInferenceChecks.fs

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

23442344
if numCurriedArgSets > 1 &&
23452345
(minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
2346-
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty)) ->
2346+
|> List.existsSquared (fun (ParamData(isParamArrayArg, _isInArg, isOutArg, optArgInfo, callerInfo, _, reflArgInfo, ty), _) ->
23472347
isParamArrayArg || isOutArg || reflArgInfo.AutoQuote || optArgInfo.IsOptional || callerInfo <> NoCallerInfo || isByrefLikeTy g m ty)) then
23482348
errorR(Error(FSComp.SR.chkCurriedMethodsCantHaveOutParams(), m))
23492349

23502350
if numCurriedArgSets = 1 then
23512351
minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
2352-
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty)) ->
2352+
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, _, _, ty), _) ->
23532353
ignore isInArg
23542354
match (optArgInfo, callerInfo) with
23552355
| _, NoCallerInfo -> ()

src/Compiler/Checking/infos.fs

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

338-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)
338+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), argInfo.Attribs
339339

340340
#if !NO_TYPEPROVIDERS
341341

@@ -1180,7 +1180,7 @@ type MethInfo =
11801180
if p.Type.TypeRef.FullName = "System.Int32" then CallerFilePath
11811181
else CallerLineNumber
11821182

1183-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo) ] ]
1183+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo), [] ] ]
11841184

11851185
| FSMeth(g, _, vref, _) ->
11861186
GetArgInfosOfMember x.IsCSharpStyleExtensionMember g vref
@@ -1201,7 +1201,7 @@ type MethInfo =
12011201
| None -> ReflectedArgInfo.None
12021202
let isOutArg = p.PUntaint((fun p -> p.IsOut && not p.IsIn), m)
12031203
let isInArg = p.PUntaint((fun p -> p.IsIn && not p.IsOut), m)
1204-
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo)] ]
1204+
ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, NoCallerInfo, reflArgInfo), [] ] ]
12051205
#endif
12061206

12071207
/// Get the signature of an abstract method slot.
@@ -1302,13 +1302,13 @@ type MethInfo =
13021302
#endif
13031303

13041304
let paramAttribs = x.GetParamAttribs(amap, m)
1305-
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun info (ParamNameAndType(nmOpt, pty)) ->
1305+
(paramAttribs, paramNamesAndTypes) ||> List.map2 (List.map2 (fun (info, attribs) (ParamNameAndType(nmOpt, pty)) ->
13061306
let (ParamAttribs(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, reflArgInfo)) = info
1307-
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty)))
1307+
ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, callerInfo, nmOpt, reflArgInfo, pty), attribs))
13081308

13091309
/// Get the ParamData objects for the parameters of a MethInfo
13101310
member x.HasParamArrayArg(amap, m, minst) =
1311-
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _)) -> isParamArrayArg)
1311+
x.GetParamDatas(amap, m, minst) |> List.existsSquared (fun (ParamData(isParamArrayArg, _, _, _, _, _, _, _), _) -> isParamArrayArg)
13121312

13131313
/// Select all the type parameters of the declaring type of a method.
13141314
///

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>]
@@ -512,10 +512,10 @@ type MethInfo =
512512
member GetCustomAttrs: unit -> ILAttributes
513513

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

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

520520
/// Get the parameter types of a method info
521521
member GetParamTypes: amap: ImportMap * m: range * minst: TType list -> TType list list

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ type internal TypeCheckInfo
571571
match meth.GetParamDatas(amap, m, meth.FormalMethodInst) with
572572
| x :: _ ->
573573
x
574-
|> List.choose (fun (ParamData (_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty)) ->
574+
|> List.choose (fun (ParamData (_isParamArray, _isInArg, _isOutArg, _optArgInfo, _callerInfo, name, _, ty), _) ->
575575
match name with
576576
| Some id -> Some(Item.ArgName(Some id, ty, Some(ArgumentContainer.Method meth), id.idRange))
577577
| None -> None)

src/Compiler/Service/ServiceDeclarationLists.fs

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

783783
| Item.CtorGroup(_, minfo :: _)
784784
| Item.MethodGroup(_, minfo :: _, _) ->
785-
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head
785+
let paramDatas = minfo.GetParamDatas(amap, m, minfo.FormalMethodInst) |> List.head |> List.map fst
786786
let retTy = minfo.GetFSharpReturnType(amap, m, minfo.FormalMethodInst)
787787
let _prettyTyparInst, prettyParams, prettyRetTyL, _prettyConstraintsL = PrettyParamsOfParamDatas g denv item.TyparInstantiation paramDatas retTy
788788
// 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
@@ -2073,10 +2073,8 @@ type FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
20732073
| M m | C m ->
20742074
[ for argTys in m.GetParamDatas(cenv.amap, range0, m.FormalMethodInst) do
20752075
yield
2076-
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty) in argTys do
2077-
// INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
2078-
// either .NET or F# parameters
2079-
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs= [] }
2076+
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty), attribs in argTys do
2077+
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs=attribs }
20802078
let m =
20812079
match nmOpt with
20822080
| Some v -> v.idRange

0 commit comments

Comments
 (0)