Skip to content

FSharpMemberOrFunctionOrValue doesn't include attributes for params in CurriedParameterGroups #13786

Open
@alfonsogarciacaro

Description

@alfonsogarciacaro

This seems to be a known issue because there are several comments in FSharpMemberOrFunctionOrValue like this one:

| M m | C m ->
[ for argTys in m.GetParamDatas(cenv.amap, range0, m.FormalMethodInst) do
yield
[ for ParamData(isParamArrayArg, isInArg, isOutArg, optArgInfo, _callerInfo, nmOpt, _reflArgInfo, pty) in argTys do
// INCOMPLETENESS: Attribs is empty here, so we can't look at attributes for
// either .NET or F# parameters
let argInfo: ArgReprInfo = { Name=nmOpt; Attribs= [] }
let m =
match nmOpt with
| Some v -> v.idRange
| None ->
defaultArg x.DeclarationLocationOpt range0
yield FSharpParameter(cenv, pty, argInfo, None, m, isParamArrayArg, isInArg, isOutArg, optArgInfo.IsOptional, false) ]
|> makeReadOnlyCollection ]
|> makeReadOnlyCollection

Not sure if this something that is not possible/easy to implement or it's been a TODO that has remained in the code base. Interestingly when members are internally represented as function values (.Data = V ...) the attributes for params can be accessed:

| V v ->
match v.ValReprInfo with
| None ->
let _, tau = v.GeneralizedType
if isFunTy cenv.g tau then
let argTysl, _typ = stripFunTy cenv.g tau
[ for ty in argTysl do
let allArguments =
if isRefTupleTy cenv.g ty
then tryDestRefTupleTy cenv.g ty
else [ty]
let m = defaultArg x.DeclarationLocationOpt range0
yield
allArguments
|> List.map (fun arg -> FSharpParameter(cenv, arg, ValReprInfo.unnamedTopArg1, m))
|> makeReadOnlyCollection ]
|> makeReadOnlyCollection

This seems to be the reason this issue hasn't surfaced in Fable until now. In Fable we sometimes use param attributes to give info about how a parameter should be compiled in the call-site. Until Fable 3 this information was directly taken from the member reference in FSharpExprPatterns.Call. It seems in this case the member is always represented as function value and the param attributes are kept. However, in Fable 4 we are using a different model where entity and member info are kept separated from the AST to make serialization easier. Because of this, the parameter info is accessed now through FSharpEntity.MembersFunctionsAndValues and apparently this causes members to be represented as methods (.Data = M ...) and the param attributes to be lost when calling CurriedParameterGroups.

@dsyme Would it be possible to fix this in FCS or is it a limitation we need to overcome somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FCSFeature ImprovementImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions