提交 ea11a9be 编写于 作者: A Anh-Dung Phan 提交者: latkin

Print ParamArray attribute instead of 'params'

fixes #109
closes #192

commit 301dfaac156f22edeef5bb55d98288ad774b5d79
Author: dungpa <phananhdung309@yahoo.com>
Date:   Thu Feb 5 09:00:46 2015 +0100

    Update test listing

commit e7f654f016825641f722d0c60a2de53a64b56027
Author: dungpa <phananhdung309@yahoo.com>
Date:   Thu Feb 5 08:42:24 2015 +0100

    Update FSharpQA tests

commit 93bd0997069713d8f0fed10d3af794bf66928e1c
Author: dungpa <phananhdung309@yahoo.com>
Date:   Wed Feb 4 21:35:52 2015 +0100

    Fix language service unit tests

commit adb4fa29eb335b24780c0f311db127ff12882ec1
Author: dungpa <phananhdung309@yahoo.com>
Date:   Wed Feb 4 13:50:18 2015 +0100

    Minor refactoring

commit a8972fe06e181077f1dcfa572b8164b567ac25b8
Author: Anh-Dung Phan <phananhdung309@yahoo.com>
Date:   Sat Jan 31 23:26:29 2015 +0000

    Fix up tests

commit 3fde68d4f709435b4d16b269f80bf6689b9ae5ec
Author: Anh-Dung Phan <phananhdung309@yahoo.com>
Date:   Sat Jan 31 23:05:06 2015 +0000

    Print ParamArray attribute instead of 'params'

    Fixed #109.
上级 f46558cf
......@@ -36,7 +36,7 @@ open Microsoft.FSharp.Compiler.Layout
open Microsoft.FSharp.Compiler.PrettyNaming
[<AutoOpen>]
module private PrintUtilities =
module internal PrintUtilities =
let bracketIfL x lyt = if x then bracketL lyt else lyt
let squareAngleL x = leftL "[<" ^^ x ^^ rightL ">]"
let angleL x = sepL "<" ^^ x ^^ rightL ">"
......@@ -70,6 +70,37 @@ module private PrintUtilities =
| [x] -> [resultFunction x (layoutFunction x)]
| (x:: rest) -> [ resultFunction x (layoutFunction x -- leftL (match rest.Length with 1 -> FSComp.SR.nicePrintOtherOverloads1() | n -> FSComp.SR.nicePrintOtherOverloadsN(n))) ]
| _ -> []
let layoutTyconRefImpl isAttribute (denv: DisplayEnv) (tcref:TyconRef) =
let demangled =
let name =
if denv.includeStaticParametersInTypeNames then
tcref.DisplayNameWithStaticParameters
elif tcref.DisplayName = tcref.DisplayNameWithStaticParameters then
tcref.DisplayName // has no static params
else
tcref.DisplayName+"<...>" // shorten
if isAttribute then
defaultArg (String.tryDropSuffix name "Attribute") name
else name
let tyconTextL = wordL demangled
if denv.shortTypeNames then
tyconTextL
else
let path = demangledPathOfCompPath tcref.CompilationPath
let path =
if denv.includeStaticParametersInTypeNames then
path
else
path |> List.map (fun s -> let i = s.IndexOf(',')
if i <> -1 then s.Substring(0,i)+"<...>" // apparently has static params, shorten
else s)
let pathText = trimPathByDisplayEnv denv path
if pathText = "" then tyconTextL else leftL pathText ^^ tyconTextL
let layoutBuiltinAttribute (denv: DisplayEnv) (attrib: BuiltinAttribInfo) =
let tcref = attrib.TyconRef
squareAngleL (layoutTyconRefImpl true denv tcref)
module private PrintIL =
......@@ -185,7 +216,8 @@ module private PrintIL =
// Layout an unnamed argument
| _, None, _ -> leftL ":"
// Layout a named argument
| true, Some nm,_ -> wordL "params" ^^ leftL (nm+":")
| true, Some nm,_ ->
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute ^^ leftL (nm + ":")
| false, Some nm,_ -> leftL (nm+":")
preL ^^ (layoutILType denv ilTyparSubst p.Type)
......@@ -550,27 +582,7 @@ module private PrintTypes =
| _ -> itemL
/// Layout a reference to a type
let layoutTyconRef (denv: DisplayEnv) (tcref:TyconRef) =
let demangled = if denv.includeStaticParametersInTypeNames then
tcref.DisplayNameWithStaticParameters
elif tcref.DisplayName = tcref.DisplayNameWithStaticParameters then
tcref.DisplayName // has no static params
else
tcref.DisplayName+"<...>" // shorten
let tyconTextL = wordL demangled
if denv.shortTypeNames then
tyconTextL
else
let path = demangledPathOfCompPath tcref.CompilationPath
let path =
if denv.includeStaticParametersInTypeNames then
path
else
path |> List.map (fun s -> let i = s.IndexOf(',')
if i <> -1 then s.Substring(0,i)+"<...>" // apparently has static params, shorten
else s)
let pathText = trimPathByDisplayEnv denv path
if pathText = "" then tyconTextL else leftL pathText ^^ tyconTextL
let layoutTyconRef denv tycon = layoutTyconRefImpl false denv tycon
/// Layout the flags of a member
let layoutMemberFlags memFlags =
......@@ -918,7 +930,12 @@ module private PrintTypes =
layoutTypeWithInfoAndPrec denv env 2 ty
// Layout a named argument
| Some id,_,isParamArray,_ ->
leftL ((if isParamArray then "params " else "") + id.idText) ^^ sepL ":" ^^ layoutTypeWithInfoAndPrec denv env 2 ty
let prefix =
if isParamArray then
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute ^^ leftL id.idText
else
leftL id.idText
prefix ^^ sepL ":" ^^ layoutTypeWithInfoAndPrec denv env 2 ty
let delimitReturnValue = if denv.useColonForReturnType then ":" else "->"
......@@ -1147,7 +1164,8 @@ module InfoMemberPrinting =
outputTy denv os pty;
// Layout a named argument
| true, Some nm,_,_ ->
bprintf os "params %s: " nm
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute |> bufferL os
bprintf os " %s: " nm
outputTy denv os pty
| false, Some nm,_,_ ->
bprintf os "%s: " nm
......
......@@ -110,7 +110,11 @@ module internal Params =
"", "", pty
// Layout a named argument
| Some nm,_,_ ->
let prefix = if isParamArrayArg then sprintf "params %s: " nm else sprintf "%s: " nm
let prefix =
if isParamArrayArg then
sprintf "%s %s: " (NicePrint.PrintUtilities.layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute |> showL) nm
else
sprintf "%s: " nm
nm, prefix,pty)
|> List.unzip3
let paramTypeAndRetLs,_ = NicePrint.layoutPrettifiedTypes denv (paramTypes@[rty])
......
......@@ -10,5 +10,5 @@ Array.iter (fun it -> System.Console.WriteLine(it)) array
array |> Array.iter (fun it -> System.Console.WriteLine(it))
//<Expects status="error" span="(7,23-7,51)" id="FS0041">A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point\. A type annotation may be needed\. Candidates: System\.Console\.WriteLine\(buffer: char \[\]\) : unit, System\.Console\.WriteLine\(format: string, params arg: obj \[\]\) : unit, System\.Console\.WriteLine\(value: bool\) : unit, System\.Console\.WriteLine\(value: char\) : unit, System\.Console\.WriteLine\(value: decimal\) : unit, System\.Console\.WriteLine\(value: float\) : unit, System\.Console\.WriteLine\(value: float32\) : unit, System\.Console\.WriteLine\(value: int\) : unit, System\.Console\.WriteLine\(value: int64\) : unit, System\.Console\.WriteLine\(value: obj\) : unit, System\.Console\.WriteLine\(value: string\) : unit, System\.Console\.WriteLine\(value: uint32\) : unit, System\.Console\.WriteLine\(value: uint64\) : unit$</Expects>
//<Expects status="error" span="(9,23-9,51)" id="FS0041">A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point\. A type annotation may be needed\. Candidates: System\.Console\.WriteLine\(buffer: char \[\]\) : unit, System\.Console\.WriteLine\(format: string, params arg: obj \[\]\) : unit, System\.Console\.WriteLine\(value: bool\) : unit, System\.Console\.WriteLine\(value: char\) : unit, System\.Console\.WriteLine\(value: decimal\) : unit, System\.Console\.WriteLine\(value: float\) : unit, System\.Console\.WriteLine\(value: float32\) : unit, System\.Console\.WriteLine\(value: int\) : unit, System\.Console\.WriteLine\(value: int64\) : unit, System\.Console\.WriteLine\(value: obj\) : unit, System\.Console\.WriteLine\(value: string\) : unit, System\.Console\.WriteLine\(value: uint32\) : unit, System\.Console\.WriteLine\(value: uint64\) : unit$</Expects>
\ No newline at end of file
//<Expects status="error" span="(7,23-7,51)" id="FS0041">A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point\. A type annotation may be needed\. Candidates: System\.Console\.WriteLine\(buffer: char \[\]\) : unit, System\.Console\.WriteLine\(format: string, \[<System\.ParamArray>\] arg: obj \[\]\) : unit, System\.Console\.WriteLine\(value: bool\) : unit, System\.Console\.WriteLine\(value: char\) : unit, System\.Console\.WriteLine\(value: decimal\) : unit, System\.Console\.WriteLine\(value: float\) : unit, System\.Console\.WriteLine\(value: float32\) : unit, System\.Console\.WriteLine\(value: int\) : unit, System\.Console\.WriteLine\(value: int64\) : unit, System\.Console\.WriteLine\(value: obj\) : unit, System\.Console\.WriteLine\(value: string\) : unit, System\.Console\.WriteLine\(value: uint32\) : unit, System\.Console\.WriteLine\(value: uint64\) : unit$</Expects>
//<Expects status="error" span="(9,23-9,51)" id="FS0041">A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point\. A type annotation may be needed\. Candidates: System\.Console\.WriteLine\(buffer: char \[\]\) : unit, System\.Console\.WriteLine\(format: string, \[<System\.ParamArray>\] arg: obj \[\]\) : unit, System\.Console\.WriteLine\(value: bool\) : unit, System\.Console\.WriteLine\(value: char\) : unit, System\.Console\.WriteLine\(value: decimal\) : unit, System\.Console\.WriteLine\(value: float\) : unit, System\.Console\.WriteLine\(value: float32\) : unit, System\.Console\.WriteLine\(value: int\) : unit, System\.Console\.WriteLine\(value: int64\) : unit, System\.Console\.WriteLine\(value: obj\) : unit, System\.Console\.WriteLine\(value: string\) : unit, System\.Console\.WriteLine\(value: uint32\) : unit, System\.Console\.WriteLine\(value: uint64\) : unit$</Expects>
// #Regression #NoMT #Printing
// Regression test for https://github.com/Microsoft/visualfsharp/issues/109
// pretty printing signatures with params arguments
//<Expects status=success>type Heterogeneous =</Expects>
//<Expects status=success> class</Expects>
//<Expects status=success> static member Echo : \[<System.ParamArray>\] args:obj \[\] -> obj \[\]</Expects>
//<Expects status=success> end</Expects>
type Heterogeneous =
static member Echo([<System.ParamArray>] args: obj[]) = args
#q;;
......@@ -32,3 +32,4 @@ ReqENU SOURCE=LazyValues03NetFx4.fsx COMPILE_ONLY=1 SCFLAGS="--nologo" FSIMODE=P
SOURCE=WidthForAFormatter.fs # WidthForAFormatter.fs
SOURCE=ToStringOnCollections.fs # ToStringOnCollections.fs
SOURCE=ParamArrayInSignatures.fsx SCFLAGS="--nologo" COMPILE_ONLY=1 FSIMODE=PIPE # ParamArrayInSignatures.fsx
......@@ -273,7 +273,7 @@ let x =
CheckErrorList content <|
fun errors ->
Assert.AreEqual(1, List.length errors)
assertContains errors "A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: System.Console.WriteLine(buffer: char []) : unit, System.Console.WriteLine(format: string, params arg: obj []) : unit, System.Console.WriteLine(value: obj) : unit, System.Console.WriteLine(value: string) : unit"
assertContains errors "A unique overload for method 'WriteLine' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: System.Console.WriteLine(buffer: char []) : unit, System.Console.WriteLine(format: string, [<System.ParamArray>] arg: obj []) : unit, System.Console.WriteLine(value: obj) : unit, System.Console.WriteLine(value: string) : unit"
[<Test>]
member public this.``InvalidMethodOverload2``() =
......
......@@ -1745,7 +1745,7 @@ We really need to rewrite some code paths here to use the real parse tree rather
)
|> Seq.tryFind(fun (i, _) -> i = 2)
match overloadWithTwoParamsOpt with
| Some(_, [_;(_name, display, _description)]) -> Assert.IsTrue(display.Contains("params args"))
| Some(_, [_;(_name, display, _description)]) -> Assert.IsTrue(display.Contains("[<System.ParamArray>] args"))
| x -> Assert.Fail(sprintf "Expected overload not found, current result %A" x)
(* DotNet functions for multi-parameterinfo tests -------------------------------------------------- *)
......
......@@ -466,7 +466,7 @@ type QuickInfoTests() =
let fileContents = """
let t = "a".Split('c')"""
this.AssertQuickInfoContainsAtEndOfMarker (fileContents, "Spl", "params separator")
this.AssertQuickInfoContainsAtEndOfMarker (fileContents, "Spl", "[<System.ParamArray>] separator")
[<Test>]
[<Category("TypeProvider")>]
......@@ -919,7 +919,7 @@ type QuickInfoTests() =
type A() =
static member Foo([<System.ParamArrayAttribute>] a : int[]) = ()
let r = A.Foo(42)""" ,
"type A","params a:" )
"type A","[<ParamArray>] a:" )
[<Test>]
member public this.``ParamsArrayArgument.OnMethod``() =
......@@ -928,7 +928,7 @@ type QuickInfoTests() =
type A() =
static member Foo([<System.ParamArrayAttribute>] a : int[]) = ()
let r = A.Foo(42)""" ,
"A.Foo","params a:" )
"A.Foo","[<System.ParamArray>] a:" )
[<Test>]
member public this.``Regression.AccessorMutator.Bug4903e``() =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册