Skip to content
Merged
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
21 changes: 12 additions & 9 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -562,19 +562,22 @@ module PrintTypes =
| _ -> comment "(* unsupported attribute argument *)"

/// Layout arguments of an attribute 'arg1, ..., argN'
and layoutAttribArgs denv args =
and layoutAttribArgs denv args props =
let argsL = args |> List.map (fun (AttribExpr(e1, _)) -> layoutAttribArg denv e1)
sepListL (rightL (tagPunctuation ",")) argsL
let propsL =
props
|> List.map (fun (AttribNamedArg(name,_, _, AttribExpr(e1, _))) ->
wordL (tagProperty name) ^^ WordL.equals ^^ layoutAttribArg denv e1)
sepListL (rightL (tagPunctuation ",")) (argsL @ propsL)

/// Layout an attribute 'Type(arg1, ..., argN)'
//
// REVIEW: we are ignoring "props" here
and layoutAttrib denv (Attrib(tcref, _, args, _props, _, _, _)) =
and layoutAttrib denv (Attrib(tcref, _, args, props, _, _, _)) =
let tcrefL = layoutTyconRefImpl true denv tcref
let argsL = bracketL (layoutAttribArgs denv args)
match args with
| [] -> tcrefL
| _ -> tcrefL ++ argsL
let argsL = bracketL (layoutAttribArgs denv args props)
if List.isEmpty args && List.isEmpty props then
tcrefL
else
tcrefL ++ argsL

and layoutILAttribElement denv arg =
match arg with
Expand Down
62 changes: 62 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Signatures/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,65 @@ type PullActions =
/// Any repo which doesn't have a master branch will have one created for it.
Log: int
}"""

[<Fact>]
let ``Attribute on record field with argument`` () =
FSharp
"""
namespace MyApp.Types

open System

type SomeEnum =
| ValueOne = 1
| ValueTwo = 2
| ValueThree = 3

[<AttributeUsage(AttributeTargets.All)>]
type MyAttribute() =
inherit System.Attribute()
member val SomeValue: SomeEnum = SomeEnum.ValueOne with get, set

type SomeTypeName =
{
/// Some Xml doc
FieldOne : string
[<MyAttribute(SomeValue = SomeEnum.ValueTwo)>]
FieldTwo : string list
/// Some other Xml doc
[<MyAttribute(SomeValue = SomeEnum.ValueThree)>]
FieldThree : string
}
"""
|> printSignatures
|> prependNewline
|> should equal
"""
namespace MyApp.Types

[<Struct>]
type SomeEnum =
| ValueOne = 1
| ValueTwo = 2
| ValueThree = 3

[<System.AttributeUsage (enum<System.AttributeTargets> (32767))>]
type MyAttribute =
inherit System.Attribute

new: unit -> MyAttribute

member SomeValue: SomeEnum

type SomeTypeName =
{

/// Some Xml doc
FieldOne: string
[<My (SomeValue = enum<SomeEnum> (2))>]
FieldTwo: string list

/// Some other Xml doc
[<My (SomeValue = enum<SomeEnum> (3))>]
FieldThree: string
}"""