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
34 changes: 23 additions & 11 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -997,34 +997,46 @@ module PrintTypes =
and layoutType denv ty =
layoutTypeWithInfo denv SimplifyTypes.typeSimplificationInfo0 ty

/// Layout '[<attrib1; attrib2>]' for parameters
and layoutAttribsOneline denv attribs =
match attribs with
| [] -> emptyL
| attribs ->
let attrsL =
[ for attr in attribs do layoutAttrib denv attr ]

squareAngleL (sepListL (rightL (tagPunctuation ";")) attrsL)

// Format each argument, including its name and type
let layoutArgInfo denv env (ty, argInfo: ArgReprInfo) =
let g = denv.g

// Detect an optional argument
let isOptionalArg = HasFSharpAttribute g g.attrib_OptionalArgumentAttribute argInfo.Attribs
let isParamArray = HasFSharpAttribute g g.attrib_ParamArrayAttribute argInfo.Attribs

match argInfo.Name, isOptionalArg, isParamArray, tryDestOptionTy g ty with
match argInfo.Name, isOptionalArg, tryDestOptionTy g ty with
// Layout an optional argument
| Some id, true, _, ValueSome ty ->
| Some id, true, ValueSome ty ->
let idL = ConvertValLogicalNameToDisplayLayout false (tagParameter >> rightL) id.idText
let attrsLayout =
argInfo.Attribs
|> List.filter (fun a -> not (IsMatchingFSharpAttribute g g.attrib_OptionalArgumentAttribute a))
|> layoutAttribsOneline denv

attrsLayout ^^
LeftL.questionMark ^^
(idL |> addColonL) ^^
layoutTypeWithInfoAndPrec denv env 2 ty

// Layout an unnamed argument
| None, _, _, _ ->
// Layout an unnamed argument
// Cannot have any attributes
| None, _, _ ->
layoutTypeWithInfoAndPrec denv env 2 ty

// Layout a named argument
| Some id, _, isParamArray, _ ->
| Some id, _, _ ->
let idL = ConvertValLogicalNameToDisplayLayout false (tagParameter >> wordL) id.idText
let prefix =
if isParamArray then
layoutBuiltinAttribute denv g.attrib_ParamArrayAttribute ^^ idL
else
idL
let prefix = layoutAttribsOneline denv argInfo.Attribs ^^ idL
(prefix |> addColonL) ^^ layoutTypeWithInfoAndPrec denv env 2 ty

let layoutCurriedArgInfos denv env argInfos =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,6 @@ let _, _ = Thing.Do()
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 501, Line 6, Col 12, Line 6, Col 22, "The member or object constructor 'Do' takes 1 argument(s) but is here given 0. The required signature is 'static member Thing.Do: i: outref<bool> -> bool'.")
(Error 501, Line 6, Col 12, Line 6, Col 22, "The member or object constructor 'Do' takes 1 argument(s) but is here given 0. The required signature is 'static member Thing.Do: [<Optional>] i: outref<bool> -> bool'.")
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Attributes

open System

type XAttribute() =
inherit Attribute()

let a ([<X>] b: int) : int = 0

type YAttribute(y: string) =
inherit Attribute()

let a2 ([<X; Y "meh">] g: string) ([<Y "buzz">] h) ([<X; Y "ii">] i: int) =
printfn "h is %i" h
g

type Boo() =
member _.Do ([<X; Y "meh">] g: string) ([<Y "buzz">] h) =
printfn "h is %i" h
g

member _.Maybe([<X>] ?s: int) = ()
member _.Forever([<X>][<Y "zzz">][<ParamArray>] args: string array) = ()
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ neg_generic_known_argument_types.fsx(9,16,9,49): typecheck error FS0041: A uniqu
Known types of arguments: ^fa * 'fb * 'a * argD: 'c when ^fa: (member X: ^b -> ^b) and ^b: (member BBBB: unit -> unit)

Candidates:
- static member A.Foo: argA1: 'a * argB1: ('a -> 'b) * argC1: ('a -> 'b) * argD: ('a -> 'b) * argZ1: 'zzz -> 'b
- static member A.Foo: argA2: 'a * argB2: ('a -> 'b) * argC2: ('b -> 'c) * argD: ('c -> 'd) * argZ2: 'zzz -> 'd
- static member A.Foo: argA1: 'a * argB1: ('a -> 'b) * argC1: ('a -> 'b) * argD: ('a -> 'b) * [<Optional>] argZ1: 'zzz -> 'b
- static member A.Foo: argA2: 'a * argB2: ('a -> 'b) * argC2: ('b -> 'c) * argD: ('c -> 'd) * [<Optional>] argZ2: 'zzz -> 'd
8 changes: 4 additions & 4 deletions tests/fsharp/typecheck/sigs/neg106.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ neg106.fs(40,18,40,32): typecheck error FS0041: No overloads match for method 'M
Known types of arguments: string * inref<int>

Available overloads:
- static member C.M: a: int * x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: string * x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: int * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: string * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'x' doesn't match

neg106.fs(41,19,41,31): typecheck error FS0041: No overloads match for method 'M'.

Known types of arguments: int * inref<int>

Available overloads:
- static member C.M: a: int * x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: string * x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: int * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: string * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'a' doesn't match

neg106.fs(49,22,49,26): typecheck error FS0001: Type mismatch. Expecting a
'byref<int>'
Expand Down
8 changes: 4 additions & 4 deletions tests/fsharp/typecheck/sigs/neg106.vsbsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ neg106.fs(40,18,40,32): typecheck error FS0041: No overloads match for method 'M
Known types of arguments: string * inref<int>

Available overloads:
- static member C.M: a: int * x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: string * x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: int * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: string * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'x' doesn't match

neg106.fs(41,19,41,31): typecheck error FS0041: No overloads match for method 'M'.

Known types of arguments: int * inref<int>

Available overloads:
- static member C.M: a: int * x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: string * x: byref<int> -> unit // Argument 'a' doesn't match
- static member C.M: a: int * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'x' doesn't match
- static member C.M: a: string * [<System.Runtime.InteropServices.Out>] x: byref<int> -> unit // Argument 'a' doesn't match

neg106.fs(49,22,49,26): typecheck error FS0001: Type mismatch. Expecting a
'byref<int>'
Expand Down
16 changes: 15 additions & 1 deletion tests/service/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,18 @@ type ImmutableArrayViaBuilder<'T>(builder: ImmutableArray<'T>.Builder) =
class end
"""
(8, 29, "type ImmutableArrayViaBuilder<'T>(builder: ImmutableArray<'T>.Builder) =", ".ctor")
#endif
#endif

[<Test>]
let ``Includes attribute for parameter`` () =
assertSignature
"val a: [<B>] c: int -> int"
"""
module Telplin

type BAttribute() =
inherit System.Attribute()

let a ([<B>] c: int) : int = 0
"""
(7, 5, "let a ([<B>] c: int) : int = 0", "a")