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
71 changes: 42 additions & 29 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,17 +2007,16 @@ and ReportNoCandidatesError (csenv:ConstraintSolverEnv) (nUnnamedCallerArgs,nNam
// No version accessible
| ([],others),_,_,_,_ ->
if isNil others then
ErrorD (Error (FSComp.SR.csMemberIsNotAccessible(methodName, (ShowAccessDomain ad)), m))
Error (FSComp.SR.csMemberIsNotAccessible(methodName, (ShowAccessDomain ad)), m)
else
ErrorD (Error (FSComp.SR.csMemberIsNotAccessible2(methodName, (ShowAccessDomain ad)), m))
Error (FSComp.SR.csMemberIsNotAccessible2(methodName, (ShowAccessDomain ad)), m)
| _,([],(cmeth::_)),_,_,_ ->

// Check all the argument types.

if (cmeth.CalledObjArgTys(m).Length <> 0) then
ErrorD(Error (FSComp.SR.csMethodIsNotAStaticMethod(methodName),m))
// Check all the argument types.
if cmeth.CalledObjArgTys(m).Length <> 0 then
Error (FSComp.SR.csMethodIsNotAStaticMethod(methodName),m)
else
ErrorD(Error (FSComp.SR.csMethodIsNotAnInstanceMethod(methodName),m))
Error (FSComp.SR.csMethodIsNotAnInstanceMethod(methodName),m)

// One method, incorrect name/arg assignment
| _,_,_,_,([],[cmeth]) ->
Expand All @@ -2038,52 +2037,65 @@ and ReportNoCandidatesError (csenv:ConstraintSolverEnv) (nUnnamedCallerArgs,nNam
else
msgNum,FSComp.SR.csMemberHasNoArgumentOrReturnProperty(methodName, id.idText, msgText),id.idRange
| [] -> (msgNum,msgText,m)
ErrorD (Error ((msgNum,msgText),msgRange))
Error ((msgNum,msgText),msgRange)

// One method, incorrect number of arguments provided by the user
| _,_,([],[cmeth]),_,_ when not cmeth.HasCorrectArity ->
let minfo = cmeth.Method
let nReqd = cmeth.TotalNumUnnamedCalledArgs
let nReqdNamed = cmeth.TotalNumAssignedNamedArgs
let nActual = cmeth.TotalNumUnnamedCallerArgs
let nreqdTyArgs = cmeth.NumCalledTyArgs
let nactualTyArgs = cmeth.NumCallerTyArgs
let signature = NicePrint.stringOfMethInfo amap m denv minfo
if nActual <> nReqd then
if nReqdNamed > 0 || cmeth.NumAssignedProps > 0 then
if nReqd > nActual then
if nActual = nReqd then
let nreqdTyArgs = cmeth.NumCalledTyArgs
let nactualTyArgs = cmeth.NumCallerTyArgs
Error (FSComp.SR.csMemberSignatureMismatchArityType(methodName, nreqdTyArgs, nactualTyArgs, signature), m)
else
let nReqdNamed = cmeth.TotalNumAssignedNamedArgs

if nReqdNamed = 0 && cmeth.NumAssignedProps = 0 then
if minfo.IsConstructor then
let couldBeNameArgs =
cmeth.ArgSets
|> List.exists (fun argSet ->
argSet.UnnamedCallerArgs
|> List.exists (fun c -> c.Expr.ToString().EndsWith "Sequential"))

if couldBeNameArgs then
Error (FSComp.SR.csCtorSignatureMismatchArityProp(methodName, nReqd, nActual, signature), m)
else
Error (FSComp.SR.csCtorSignatureMismatchArity(methodName, nReqd, nActual, signature), m)
else
Error (FSComp.SR.csMemberSignatureMismatchArity(methodName, nReqd, nActual, signature), m)
else
if nReqd > nActual then
let diff = nReqd - nActual
let missingArgs = List.drop nReqd cmeth.AllUnnamedCalledArgs
match NamesOfCalledArgs missingArgs with
| [] ->
| [] ->
if nActual = 0 then
ErrorD (Error (FSComp.SR.csMemberSignatureMismatch(methodName, diff, signature), m))
Error (FSComp.SR.csMemberSignatureMismatch(methodName, diff, signature), m)
else
ErrorD (Error (FSComp.SR.csMemberSignatureMismatch2(methodName, diff, signature), m))
Error (FSComp.SR.csMemberSignatureMismatch2(methodName, diff, signature), m)
| names ->
let str = String.concat ";" (pathOfLid names)
if nActual = 0 then
ErrorD (Error (FSComp.SR.csMemberSignatureMismatch3(methodName, diff, signature, str), m))
else
ErrorD (Error (FSComp.SR.csMemberSignatureMismatch4(methodName, diff, signature, str), m))
Error (FSComp.SR.csMemberSignatureMismatch3(methodName, diff, signature, str), m)
else
Error (FSComp.SR.csMemberSignatureMismatch4(methodName, diff, signature, str), m)
else
ErrorD (Error (FSComp.SR.csMemberSignatureMismatchArityNamed(methodName, (nReqd+nReqdNamed), nActual, nReqdNamed, signature), m))
else
ErrorD (Error (FSComp.SR.csMemberSignatureMismatchArity(methodName, nReqd, nActual, signature), m))
else
ErrorD (Error (FSComp.SR.csMemberSignatureMismatchArityType(methodName, nreqdTyArgs, nactualTyArgs, signature), m))
Error (FSComp.SR.csMemberSignatureMismatchArityNamed(methodName, (nReqd+nReqdNamed), nActual, nReqdNamed, signature), m)

// One or more accessible, all the same arity, none correct
| ((cmeth :: cmeths2),_),_,_,_,_ when not cmeth.HasCorrectArity && cmeths2 |> List.forall (fun cmeth2 -> cmeth.TotalNumUnnamedCalledArgs = cmeth2.TotalNumUnnamedCalledArgs) ->
ErrorD (Error (FSComp.SR.csMemberNotAccessible(methodName, nUnnamedCallerArgs, methodName, cmeth.TotalNumUnnamedCalledArgs),m))
Error (FSComp.SR.csMemberNotAccessible(methodName, nUnnamedCallerArgs, methodName, cmeth.TotalNumUnnamedCalledArgs),m)
// Many methods, all with incorrect number of generic arguments
| _,_,_,([],(cmeth :: _)),_ ->
let msg = FSComp.SR.csIncorrectGenericInstantiation((ShowAccessDomain ad), methodName, cmeth.NumCallerTyArgs)
ErrorD (Error (msg,m))
Error (msg,m)
// Many methods of different arities, all incorrect
| _,_,([],(cmeth :: _)),_,_ ->
let minfo = cmeth.Method
ErrorD (Error (FSComp.SR.csMemberOverloadArityMismatch(methodName, cmeth.TotalNumUnnamedCallerArgs, (List.sum minfo.NumArgs)),m))
Error (FSComp.SR.csMemberOverloadArityMismatch(methodName, cmeth.TotalNumUnnamedCallerArgs, (List.sum minfo.NumArgs)),m)
| _ ->
let msg =
if nNamedCallerArgs = 0 then
Expand All @@ -2095,7 +2107,8 @@ and ReportNoCandidatesError (csenv:ConstraintSolverEnv) (nUnnamedCallerArgs,nNam
else
let sample = s.MinimumElement
FSComp.SR.csNoMemberTakesTheseArguments3((ShowAccessDomain ad), methodName, nUnnamedCallerArgs, sample)
ErrorD (Error (msg,m))
Error (msg,m)
|> ErrorD


// Resolve the overloading of a method
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ csCtorHasNoArgumentOrReturnProperty,"The object constructor '%s' has no argument
499,csMemberSignatureMismatch4,"The member or object constructor '%s' requires %d additional argument(s). The required signature is '%s'. Some names for missing arguments are %s."
500,csMemberSignatureMismatchArityNamed,"The member or object constructor '%s' requires %d argument(s) but is here given %d unnamed and %d named argument(s). The required signature is '%s'."
501,csMemberSignatureMismatchArity,"The member or object constructor '%s' takes %d argument(s) but is here given %d. The required signature is '%s'."
501,csCtorSignatureMismatchArity,"The object constructor '%s' takes %d argument(s) but is here given %d. The required signature is '%s'."
501,csCtorSignatureMismatchArityProp,"The object constructor '%s' takes %d argument(s) but is here given %d. The required signature is '%s'. If some of the arguments are meant to assign values to properties, consider separating those arguments with a comma (',')."
502,csMemberSignatureMismatchArityType,"The member or object constructor '%s' takes %d type argument(s) but is here given %d. The required signature is '%s'."
503,csMemberNotAccessible,"A member or object constructor '%s' taking %d arguments is not accessible from this code location. All accessible versions of method '%s' take %d arguments."
504,csIncorrectGenericInstantiation,"Incorrect generic instantiation. No %s member named '%s' takes %d generic arguments."
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/typecheck/sigs/neg15.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ neg15.fs(190,1,190,6): typecheck error FS0491: The member or object constructor

neg15.fs(191,1,191,8): typecheck error FS0491: The member or object constructor 'SM' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.

neg15.fs(204,11,204,16): typecheck error FS0501: The member or object constructor 'X2' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> X2'.
neg15.fs(204,11,204,16): typecheck error FS0501: The object constructor 'X2' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> X2'.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes #Diagnostics
// Regression test for FSHARP1.0:5406
// Scenario #2: I'm writing my own custom IComparable implementation - don't bother giving me one
//<Expects status="error" span="(7,3-7,23)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(7,3-7,23)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>

[<StructuralEquality>]
[<StructuralComparison(false)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes #Diagnostics
// Regression test for FSHARP1.0:5406
// Scenario #1: I'm not writing my own custom IComparable implementation, assume the reference equality
//<Expects status="error" span="(7,3-7,23)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(7,3-7,23)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>

[<StructuralEquality>]
[<StructuralComparison(false)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes

//<Expects status="error" span="(7,5-7,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The member or object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
module M01 =
[<ReferenceEquality(true)>]
[<StructuralComparison(true)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes
//<Expects status="error" span="(8,5-8,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(10,5-10,23)" id="FS0501">The member or object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(10,5-10,23)" id="FS0501">The object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>


module M02 =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes

//<Expects status="error" span="(7,5-7,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>

module M03 =
[<ReferenceEquality(true)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes

//<Expects status="error" span="(7,5-7,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The member or object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
module M04 =
[<ReferenceEquality(true)>]
[<StructuralComparison(false)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The member or object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(9,5-9,23)" id="FS0501">The object constructor 'StructuralEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralEqualityAttribute'\.$</Expects>

module M05 =
[<ReferenceEquality(true)>]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #TypesAndModules #GeneratedEqualityAndHashing #Attributes

//<Expects status="error" span="(7,5-7,22)" id="FS0501">The member or object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The member or object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>
//<Expects status="error" span="(7,5-7,22)" id="FS0501">The object constructor 'ReferenceEqualityAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> ReferenceEqualityAttribute'\.$</Expects>
//<Expects status="error" span="(8,5-8,25)" id="FS0501">The object constructor 'StructuralComparisonAttribute' takes 0 argument\(s\) but is here given 1\. The required signature is 'new : unit -> StructuralComparisonAttribute'\.$</Expects>

module M06 =
[<ReferenceEquality(true)>]
Expand Down
Loading