Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -975,15 +975,16 @@ let AdjustValSynInfoInSignature g ty (SynValInfo(argsData, retData) as sigMD) =
sigMD


let TranslateTopArgSynInfo (cenv: cenv) isArg m tcAttributes (SynArgInfo(Attributes attrs, isOpt, nm)) =
let TranslateTopArgSynInfo (cenv: cenv) isArg (m: range) tcAttributes (SynArgInfo(Attributes attrs, isOpt, nm)) =
// Synthesize an artificial "OptionalArgument" attribute for the parameter
let optAttrs =
let optAttrs: SynAttribute list =
if isOpt then
[ ( { TypeName=SynLongIdent(pathToSynLid m ["Microsoft";"FSharp";"Core";"OptionalArgument"], [], [None;None;None;None])
ArgExpr=mkSynUnit m
Target=None
AppliesToGetterAndSetter=false
Range=m} : SynAttribute) ]
let m = m.MakeSynthetic()
[ { TypeName = SynLongIdent(pathToSynLid m ["Microsoft"; "FSharp"; "Core"; "OptionalArgument"], [], [None; None; None; None])
ArgExpr = mkSynUnit m
Target = None
AppliesToGetterAndSetter = false
Range = m } ]
else
[]

Expand All @@ -993,8 +994,7 @@ let TranslateTopArgSynInfo (cenv: cenv) isArg m tcAttributes (SynArgInfo(Attribu
if not isArg && Option.isSome nm then
errorR(Error(FSComp.SR.tcReturnValuesCannotHaveNames(), m))

// Call the attribute checking function
let attribs = tcAttributes (optAttrs@attrs)
let attribs = tcAttributes (optAttrs @ attrs)

let key = nm |> Option.map (fun id -> id.idText, id.idRange)

Expand Down
13 changes: 13 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,19 @@ module Delegates =
symbols["EventHandler"].IsDelegate |> shouldEqual true
symbols["Action"].IsDelegate |> shouldEqual true

module Parameters =
[<Fact>]
let ``Optional 01`` () =
let _, checkResults = getParseAndCheckResults """
type T =
static member M(?a) = ()
"""
checkResults.GetAllUsesOfAllSymbolsInFile()
|> Seq.filter (fun su -> su.Range.StartLine = 3)
|> Seq.map _.Symbol.DisplayName
|> Seq.toList
|> shouldEqual [ "M"; "a" ]

module MetadataAsText =
[<Fact>]
let ``TryGetMetadataAsText returns metadata for external enum field`` () =
Expand Down
Loading