-
Notifications
You must be signed in to change notification settings - Fork 831
warning for mismatched param names #3527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
We can put it in new project templates and enable it by default in the coreclr projects. |
KevinRansom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs some tests case too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like maxerrors ... keeps the insanity down.
src/fsharp/SignatureConformance.fs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the comparison be locale aware, or be StringCompare.Ordinal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere else in signature conformance checking we just use default F# string equality i.e. System.String.Equals(string1,string2), e.g.
if implTycon.LogicalName <> sigTycon.LogicalName then (errorR (Error (FSComp.SR.DefinitionsInSigAndImplNotCompatibleNamesDiffer(implTycon.TypeOrMeasureKind.ToString(),sigTycon.LogicalName,implTycon.LogicalName),m)); false) else
if implTycon.CompiledName <> sigTycon.CompiledName then (errorR (Error (FSComp.SR.DefinitionsInSigAndImplNotCompatibleNamesDiffer(implTycon.TypeOrMeasureKind.ToString(),sigTycon.CompiledName,implTycon.CompiledName),m)); false) else
If we change it in one place we'd need to change it everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ... but what is the right thing to do?
It may be that locale aware case sensitive is the right thing to do. It's not clear to me is all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can't change this at this stage - all the name lookups in the compiler are based on exact string equality.
Also, part of the intent of using the signature names is to make sure that the .NET/IL/C#/debug and F# views of named arguments are the same. We don't know what equality check is used by visual studio when you mouse-hover over an identifier and it tries to look it up.
In any case, it's an orthogonal issue to this PR
|
@dsyme isn't the better fix to use the implementation parameter names in IL instead of the signature parameter names? Then we don't even need the warning - it will just work by default. |
That would be a breaking change since the C#/.NET view of consuming the assembly would change. Also the C#/.NET view would be logically different to the F# view, e.g. for named arguments, which greatly disturbs me. |
I'm ok with that approach. |
|
How does C# get around this for interface methods that have different parameter names than the parameter names on the same method in an implementing class? |
|
I've
Still need to adjust the templates |
|
@saul For C#
from using System;
namespace ConsoleApp1
{
class A
{
public virtual void M(string x, string y) { System.Console.WriteLine("A.M x = {0}, y = {1}", x, y); }
}
class B : A
{
public override void M(string y, string x) { System.Console.WriteLine("B.M x = {0}, y = {1}", x, y); }
}
class Program
{
static void Main(string[] args)
{
(new A()).M(x: "XX", y: "YY");
(new B()).M(x: "XX", y: "YY");
((A)(new B())).M(x: "XX", y: "YY");
System.Console.ReadLine();
}
}
}FWIW I think the optional feature is justified just on the basis of code hygiene and correctness alone |
|
@saul I can definitely see the case for also implementing an optional warning on overrides |
|
I think I'm being blind but I can't fix the codefix in this PR? |
|
@saul Yes, missed a file - now added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use this logic? I saw this used somewhere else and this isn't correct - there's many cases when you want to use ``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saul Yes, I agree. I will find the right compiler helpe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if my variable name ends in '?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like: [^']+'(.+)'[^']+'(.+)'[^']+
Edit: actually it looks like .+'(.+)'.+'(.+)'.+ also works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saul Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re variable name ending in ' - good point. Not sure what to do about this
|
Cheers Don. Looks like we're also missing the FSharp.Editor.fsproj change, too? |
|
This is ready once CI is green, subject to review @KevinRansom I presume the F# templates for .NET SDK are in the .NET SDK repo? |
@saul See https://github.com/Microsoft/visualfsharp/pull/3527/files#diff-2c15e8a33254afafc0e96c4f069e0aadR96 |
|
@saul Thanks for the feedback so far. If you could give it a go that would be great |
saul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At work at the minute so this is just by eye! Looks great though - glad we’ve fixed one of the debugging oddities.
|
@dsyme for coreclr put it in here: https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props |
|
@dotnet-bot test Windows_NT Release_ci_part1 Build please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment really necessary? Also I think this should be: <OtherFlags>$(OtherFlags) --warnon:3218</OtherFlags> . We don't want to override any flags that were previously set (e.g. if there is an <Import> at the top of the project). That's bitten me before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes to both, but @KevinRansom asked me to drop these changes in any case, he'll do them separately
|
@KevinRansom This is ready - when you merge can you create the tracking issue for templates? Thanks |
This is the proposed fix for #3467
Basically we will now show a warning when signature files and implementation files have mismatched argument names
This is WIP because wee must fix up the (many) occurrences of this problem in FSharp.Core and the compiler itself.
We also have to decide if the warning is on or off by default. Given the severity of the problem for the debugging experience (See linked bug) I'm sure it should be on by default - even if that means upgrading F# version requires adding a --nowarn or changing code