Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea11a9b

Browse files
dungpalatkin
authored andcommitted
Print ParamArray attribute instead of 'params'
fixesdotnet#109closesdotnet#192commit301dfaaAuthor: dungpa <phananhdung309@yahoo.com>Date: Thu Feb 5 09:00:46 2015 +0100 Update test listingcommite7f654fAuthor: dungpa <phananhdung309@yahoo.com>Date: Thu Feb 5 08:42:24 2015 +0100 Update FSharpQA testscommit93bd099Author: dungpa <phananhdung309@yahoo.com>Date: Wed Feb 4 21:35:52 2015 +0100 Fix language service unit testscommitadb4fa2Author: dungpa <phananhdung309@yahoo.com>Date: Wed Feb 4 13:50:18 2015 +0100 Minor refactoringcommita8972feAuthor: Anh-Dung Phan <phananhdung309@yahoo.com>Date: Sat Jan 31 23:26:29 2015 +0000 Fix up testscommit3fde68dAuthor: Anh-Dung Phan <phananhdung309@yahoo.com>Date: Sat Jan 31 23:05:06 2015 +0000 Print ParamArray attribute instead of 'params'Fixeddotnet#109.
1 parentf46558c commitea11a9b

File tree

8 files changed

+69
-33
lines changed

8 files changed

+69
-33
lines changed

‎src/fsharp/NicePrint.fs‎

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open Microsoft.FSharp.Compiler.Layout
3636
openMicrosoft.FSharp.Compiler.PrettyNaming
3737

3838
[<AutoOpen>]
39-
moduleprivatePrintUtilities=
39+
moduleinternalPrintUtilities=
4040
letbracketIfL x lyt=if xthen bracketL lytelse lyt
4141
letsquareAngleL x= leftL"[<"^^ x^^ rightL">]"
4242
letangleL x= sepL"<"^^ x^^ rightL">"
@@ -70,6 +70,37 @@ module private PrintUtilities =
7070
|[x]->[resultFunction x(layoutFunction x)]
7171
|(x:: rest)->[ resultFunction x(layoutFunction x-- leftL(match rest.Lengthwith1-> FSComp.SR.nicePrintOtherOverloads1()| n-> FSComp.SR.nicePrintOtherOverloadsN(n)))]
7272
|_->[]
73+
74+
letlayoutTyconRefImpl isAttribute(denv:DisplayEnv)(tcref:TyconRef)=
75+
letdemangled=
76+
letname=
77+
if denv.includeStaticParametersInTypeNamesthen
78+
tcref.DisplayNameWithStaticParameters
79+
elif tcref.DisplayName= tcref.DisplayNameWithStaticParametersthen
80+
tcref.DisplayName// has no static params
81+
else
82+
tcref.DisplayName+"<...>"// shorten
83+
if isAttributethen
84+
defaultArg(String.tryDropSuffix name"Attribute") name
85+
else name
86+
lettyconTextL= wordL demangled
87+
if denv.shortTypeNamesthen
88+
tyconTextL
89+
else
90+
letpath= demangledPathOfCompPath tcref.CompilationPath
91+
letpath=
92+
if denv.includeStaticParametersInTypeNamesthen
93+
path
94+
else
95+
path|> List.map(fun s->leti= s.IndexOf(',')
96+
if i<>-1then s.Substring(0,i)+"<...>"// apparently has static params, shorten
97+
else s)
98+
letpathText= trimPathByDisplayEnv denv path
99+
if pathText=""then tyconTextLelse leftL pathText^^ tyconTextL
100+
101+
letlayoutBuiltinAttribute(denv:DisplayEnv)(attrib:BuiltinAttribInfo)=
102+
lettcref= attrib.TyconRef
103+
squareAngleL(layoutTyconRefImpltrue denv tcref)
73104

74105
moduleprivatePrintIL=
75106

@@ -185,7 +216,8 @@ module private PrintIL =
185216
// Layout an unnamed argument
186217
|_, None,_-> leftL":"
187218
// Layout a named argument
188-
|true, Some nm,_-> wordL"params"^^ leftL(nm+":")
219+
|true, Some nm,_->
220+
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute^^ leftL(nm+":")
189221
|false, Some nm,_-> leftL(nm+":")
190222
preL^^(layoutILType denv ilTyparSubst p.Type)
191223

@@ -550,27 +582,7 @@ module private PrintTypes =
550582
|_-> itemL
551583

552584
/// Layout a reference to a type
553-
letlayoutTyconRef(denv:DisplayEnv)(tcref:TyconRef)=
554-
letdemangled=if denv.includeStaticParametersInTypeNamesthen
555-
tcref.DisplayNameWithStaticParameters
556-
elif tcref.DisplayName= tcref.DisplayNameWithStaticParametersthen
557-
tcref.DisplayName// has no static params
558-
else
559-
tcref.DisplayName+"<...>"// shorten
560-
lettyconTextL= wordL demangled
561-
if denv.shortTypeNamesthen
562-
tyconTextL
563-
else
564-
letpath= demangledPathOfCompPath tcref.CompilationPath
565-
letpath=
566-
if denv.includeStaticParametersInTypeNamesthen
567-
path
568-
else
569-
path|> List.map(fun s->leti= s.IndexOf(',')
570-
if i<>-1then s.Substring(0,i)+"<...>"// apparently has static params, shorten
571-
else s)
572-
letpathText= trimPathByDisplayEnv denv path
573-
if pathText=""then tyconTextLelse leftL pathText^^ tyconTextL
585+
letlayoutTyconRef denv tycon= layoutTyconRefImplfalse denv tycon
574586

575587
/// Layout the flags of a member
576588
letlayoutMemberFlags memFlags=
@@ -918,7 +930,12 @@ module private PrintTypes =
918930
layoutTypeWithInfoAndPrec denv env2 ty
919931
// Layout a named argument
920932
| Some id,_,isParamArray,_->
921-
leftL((if isParamArraythen"params"else"")+ id.idText)^^ sepL":"^^ layoutTypeWithInfoAndPrec denv env2 ty
933+
letprefix=
934+
if isParamArraythen
935+
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute^^ leftL id.idText
936+
else
937+
leftL id.idText
938+
prefix^^ sepL":"^^ layoutTypeWithInfoAndPrec denv env2 ty
922939

923940
letdelimitReturnValue=if denv.useColonForReturnTypethen":"else"->"
924941

@@ -1147,7 +1164,8 @@ module InfoMemberPrinting =
11471164
outputTy denv os pty;
11481165
// Layout a named argument
11491166
|true, Some nm,_,_->
1150-
bprintf os"params%s:" nm
1167+
layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute|> bufferL os
1168+
bprintf os"%s:" nm
11511169
outputTy denv os pty
11521170
|false, Some nm,_,_->
11531171
bprintf os"%s:" nm

‎src/fsharp/vs/service.fs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ module internal Params =
110110
"","", pty
111111
// Layout a named argument
112112
| Some nm,_,_->
113-
letprefix=if isParamArrayArgthen sprintf"params%s:" nmelse sprintf"%s:" nm
113+
letprefix=
114+
if isParamArrayArgthen
115+
sprintf"%s%s:"(NicePrint.PrintUtilities.layoutBuiltinAttribute denv denv.g.attrib_ParamArrayAttribute|> showL) nm
116+
else
117+
sprintf"%s:" nm
114118
nm, prefix,pty)
115119
|> List.unzip3
116120
letparamTypeAndRetLs,_= NicePrint.layoutPrettifiedTypes denv(paramTypes@[rty])

‎tests/fsharpqa/Source/Conformance/InferenceProcedures/TypeInference/E_LeftToRightOverloadResolution01.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ Array.iter (fun it -> System.Console.WriteLine(it)) array
1010

1111
array|> Array.iter(fun it-> System.Console.WriteLine(it))
1212

13-
//<Expects status="error" span="(7,23-7,51)">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>
14-
//<Expects status="error" span="(9,23-9,51)">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>
13+
//<Expects status="error" span="(7,23-7,51)">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>
14+
//<Expects status="error" span="(9,23-9,51)">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>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #Regression #NoMT #Printing
2+
// Regression test for https://github.com/Microsoft/visualfsharp/issues/109
3+
4+
// pretty printing signatures with params arguments
5+
//<Expects status=success>type Heterogeneous =</Expects>
6+
//<Expects status=success> class</Expects>
7+
//<Expects status=success> static member Echo : \[<System.ParamArray>\] args:obj \[\] -> obj \[\]</Expects>
8+
//<Expects status=success> end</Expects>
9+
10+
typeHeterogeneous=
11+
static memberEcho([<System.ParamArray>]args:obj[])= args
12+
13+
#q;;

‎tests/fsharpqa/Source/Printing/env.lst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ ReqENUSOURCE=LazyValues03NetFx4.fsx COMPILE_ONLY=1 SCFLAGS="--nologo" FSIMODE=P
3232

3333
SOURCE=WidthForAFormatter.fs# WidthForAFormatter.fs
3434
SOURCE=ToStringOnCollections.fs# ToStringOnCollections.fs
35+
SOURCE=ParamArrayInSignatures.fsx SCFLAGS="--nologo" COMPILE_ONLY=1 FSIMODE=PIPE# ParamArrayInSignatures.fsx

‎vsintegration/src/unittests/Tests.LanguageService.ErrorList.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ let x =
273273
CheckErrorList content<|
274274
fun errors->
275275
Assert.AreEqual(1, List.length errors)
276-
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"
276+
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"
277277

278278
[<Test>]
279279
memberpublicthis.``InvalidMethodOverload2``()=

‎vsintegration/src/unittests/Tests.LanguageService.ParameterInfo.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ We really need to rewrite some code paths here to use the real parse tree rather
17451745
)
17461746
|> Seq.tryFind(fun(i,_)-> i=2)
17471747
match overloadWithTwoParamsOptwith
1748-
| Some(_,[_;(_name, display,_description)])-> Assert.IsTrue(display.Contains("params args"))
1748+
| Some(_,[_;(_name, display,_description)])-> Assert.IsTrue(display.Contains("[<System.ParamArray>] args"))
17491749
| x-> Assert.Fail(sprintf"Expected overload not found, current result%A" x)
17501750

17511751
(* DotNet functions for multi-parameterinfo tests --------------------------------------------------*)

‎vsintegration/src/unittests/Tests.LanguageService.QuickInfo.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ type QuickInfoTests() =
466466
letfileContents="""
467467
let t = "a".Split('c')"""
468468

469-
this.AssertQuickInfoContainsAtEndOfMarker(fileContents,"Spl","params separator")
469+
this.AssertQuickInfoContainsAtEndOfMarker(fileContents,"Spl","[<System.ParamArray>] separator")
470470

471471
[<Test>]
472472
[<Category("TypeProvider")>]
@@ -919,7 +919,7 @@ type QuickInfoTests() =
919919
type A() =
920920
static member Foo([<System.ParamArrayAttribute>] a : int[]) = ()
921921
let r = A.Foo(42)""",
922-
"type A","params a:")
922+
"type A","[<ParamArray>] a:")
923923

924924
[<Test>]
925925
memberpublicthis.``ParamsArrayArgument.OnMethod``()=
@@ -928,7 +928,7 @@ type QuickInfoTests() =
928928
type A() =
929929
static member Foo([<System.ParamArrayAttribute>] a : int[]) = ()
930930
let r = A.Foo(42)""",
931-
"A.Foo","params a:")
931+
"A.Foo","[<System.ParamArray>] a:")
932932

933933
[<Test>]
934934
memberpublicthis.``Regression.AccessorMutator.Bug4903e``()=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp