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

Commit3fde68d

Browse files
committed
Print ParamArray attribute instead of 'params'
Fixeddotnet#109.
1 parent22fc2c7 commit3fde68d

File tree

3 files changed

+57
-25
lines changed

3 files changed

+57
-25
lines changed

‎src/fsharp/NicePrint.fs‎

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ module private PrintUtilities =
7171
|(x:: rest)->[ resultFunction x(layoutFunction x-- leftL(match rest.Lengthwith1-> FSComp.SR.nicePrintOtherOverloads1()| n-> FSComp.SR.nicePrintOtherOverloadsN(n)))]
7272
|_->[]
7373

74+
/// Layout a reference to a type
75+
letlayoutTyconRefImpl isAttribute(denv:DisplayEnv)(tcref:TyconRef)=
76+
letdemangled=
77+
letname=
78+
if denv.includeStaticParametersInTypeNamesthen
79+
tcref.DisplayNameWithStaticParameters
80+
elif tcref.DisplayName= tcref.DisplayNameWithStaticParametersthen
81+
tcref.DisplayName// has no static params
82+
else
83+
tcref.DisplayName+"<...>"// shorten
84+
if isAttributethen
85+
defaultArg(String.tryDropSuffix name"Attribute") name
86+
else name
87+
lettyconTextL= wordL demangled
88+
if denv.shortTypeNamesthen
89+
tyconTextL
90+
else
91+
letpath= demangledPathOfCompPath tcref.CompilationPath
92+
letpath=
93+
if denv.includeStaticParametersInTypeNamesthen
94+
path
95+
else
96+
path|> List.map(fun s->leti= s.IndexOf(',')
97+
if i<>-1then s.Substring(0,i)+"<...>"// apparently has static params, shorten
98+
else s)
99+
letpathText= trimPathByDisplayEnv denv path
100+
if pathText=""then tyconTextLelse leftL pathText^^ tyconTextL
101+
102+
letlayoutTyconAttribute(denv:DisplayEnv)(tcref:TyconRef)=
103+
squareAngleL(layoutTyconRefImpltrue denv tcref)
104+
74105
moduleprivatePrintIL=
75106

76107
openMicrosoft.FSharp.Compiler.AbstractIL.IL
@@ -185,7 +216,9 @@ 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+
lettyp= denv.g.attrib_ParamArrayAttribute.TyconRef
221+
layoutTyconAttribute denv typ^^ leftL(nm+":")
189222
|false, Some nm,_-> leftL(nm+":")
190223
preL^^(layoutILType denv ilTyparSubst p.Type)
191224

@@ -549,28 +582,7 @@ module private PrintTypes =
549582
| Internal,Private-> wordL"private"++ itemL// print modifier, since more specific than context
550583
|_-> itemL
551584

552-
/// 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,13 @@ 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+
lettyp= denv.g.attrib_ParamArrayAttribute.TyconRef
936+
layoutTyconAttribute denv typ^^ leftL id.idText
937+
else
938+
leftL id.idText
939+
prefix^^ sepL":"^^ layoutTypeWithInfoAndPrec denv env2 ty
922940

923941
letdelimitReturnValue=if denv.useColonForReturnTypethen":"else"->"
924942

@@ -1147,7 +1165,9 @@ module InfoMemberPrinting =
11471165
outputTy denv os pty;
11481166
// Layout a named argument
11491167
|true, Some nm,_,_->
1150-
bprintf os"params%s:" nm
1168+
lettyp= denv.g.attrib_ParamArrayAttribute.TyconRef
1169+
layoutTyconAttribute denv typ|> bufferL os
1170+
bprintf os"%s:" nm
11511171
outputTy denv os pty
11521172
|false, Some nm,_,_->
11531173
bprintf os"%s:" nm
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// #Regression #NoMT #Printing
2+
#light
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>\] obj \[\] -> obj \[\]</Expects>
8+
//<Expects status=success> end</Expects>
9+
10+
typeHeterogeneous=
11+
static memberEcho([<System.ParamArray>]args:obj[])= args

‎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.fs SCFLAGS="--nologo" COMPILE_ONLY=1 FSIMODE=PIPE# ParamArrayInSignatures.fs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp