Skip to content

Commit 1617a15

Browse files
authored
Fix 14097 (#14131)
* Fix 14097 * Fix 14097
1 parent 8ba53ff commit 1617a15

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8556,7 +8556,12 @@ and TcTraitItemThen (cenv: cenv) overallTy env objOpt traitInfo tpenv mItem dela
85568556
applicableExpr, exprTy
85578557
| _ ->
85588558
let vs, ves = argTys |> List.mapi (fun i ty -> mkCompGenLocal mItem ("arg" + string i) ty) |> List.unzip
8559-
let traitCall = Expr.Op (TOp.TraitCall traitInfo, [], objArgs@ves, mItem)
8559+
// Account for a unit mismtach in logical v. compiled arguments
8560+
let compiledArgExprs =
8561+
match argTys, traitInfo.GetCompiledArgumentTypes() with
8562+
| [_], [] -> []
8563+
| _ -> ves
8564+
let traitCall = Expr.Op (TOp.TraitCall traitInfo, [], objArgs@compiledArgExprs, mItem)
85608565
let v, body = MultiLambdaToTupledLambda g vs traitCall
85618566
let expr = mkLambda mItem v (body, retTy)
85628567
let exprTy = tyOfExpr g expr

tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/testFiles/CheckNewSyntax.fs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@ module CheckNewSyntax =
44

55
type MyType() =
66
static member val StaticProperty = 0 with get, set
7-
static member StaticMethod x = x + 5
7+
static member StaticMethod0 () = 5
8+
static member StaticMethod1 x = x + 5
9+
static member StaticMethod2 (x, y) = x + y + 5
810
member val Length = 0 with get, set
911
member _.Item with get x = "Hello"
10-
member _.InstanceMethod x = x + 5
12+
member _.InstanceMethod0 () = 5
13+
member _.InstanceMethod1 x = x + 5
14+
member _.InstanceMethod2 (x, y) = x + y + 5
1115

1216
// Check that "property" and "get_ method" constraints are considered logically equivalent
1317
let inline f_StaticProperty<'T when 'T : (static member StaticProperty: int) >() : int = 'T.StaticProperty
1418

15-
let inline f_StaticMethod<'T when 'T : (static member StaticMethod: int -> int) >() : int = 'T.StaticMethod(3)
19+
let inline f_StaticMethod0<'T when 'T : (static member StaticMethod0: unit -> int) >() : int = 'T.StaticMethod0()
20+
21+
let inline f_StaticMethod1<'T when 'T : (static member StaticMethod1: int -> int) >() : int = 'T.StaticMethod1(3)
22+
23+
let inline f_StaticMethod2<'T when 'T : (static member StaticMethod2: int * int -> int) >() : int = 'T.StaticMethod2(3, 3)
1624

1725
let inline f_set_StaticProperty<'T when 'T : (static member StaticProperty: int with set) >() = 'T.set_StaticProperty(3)
1826

19-
let inline f_InstanceMethod<'T when 'T : (member InstanceMethod: int -> int) >(x: 'T) : int = x.InstanceMethod(3)
27+
let inline f_InstanceMethod0<'T when 'T : (member InstanceMethod0: unit -> int) >(x: 'T) : int = x.InstanceMethod0()
28+
29+
let inline f_InstanceMethod1<'T when 'T : (member InstanceMethod1: int -> int) >(x: 'T) : int = x.InstanceMethod1(3)
30+
31+
let inline f_InstanceMethod2<'T when 'T : (member InstanceMethod2: int * int -> int) >(x: 'T) : int = x.InstanceMethod2(3, 3)
2032

2133
let inline f_Length<'T when 'T : (member Length: int) >(x: 'T) = x.Length
2234

@@ -33,7 +45,13 @@ module CheckNewSyntax =
3345
//let inline f_set_Length2<'T when 'T : (member Length: int with set) >(x: 'T) = x.Length <- 3
3446
//let inline f_Item2<'T when 'T : (member Item: int -> string with get) >(x: 'T) = x[3]
3547

36-
if f_StaticMethod<MyType>() <> 8 then
48+
if f_StaticMethod0<MyType>() <> 5 then
49+
failwith "Unexpected result"
50+
51+
if f_StaticMethod1<MyType>() <> 8 then
52+
failwith "Unexpected result"
53+
54+
if f_StaticMethod2<MyType>() <> 11 then
3755
failwith "Unexpected result"
3856

3957
if f_set_StaticProperty<MyType>() <> () then
@@ -47,7 +65,13 @@ module CheckNewSyntax =
4765
if f_Length(myInstance) <> 0 then
4866
failwith "Unexpected result"
4967

50-
if f_InstanceMethod(myInstance) <> 8 then
68+
if f_InstanceMethod0(myInstance) <> 5 then
69+
failwith "Unexpected result"
70+
71+
if f_InstanceMethod1(myInstance) <> 8 then
72+
failwith "Unexpected result"
73+
74+
if f_InstanceMethod2(myInstance) <> 11 then
5175
failwith "Unexpected result"
5276

5377
if f_set_Length(myInstance) <> () then

0 commit comments

Comments
 (0)