Skip to content

Conversation

@dsyme
Copy link
Contributor

@dsyme dsyme commented Aug 30, 2017

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

@KevinRansom
Copy link
Contributor

KevinRansom commented Aug 31, 2017

We can put it in new project templates and enable it by default in the coreclr projects.
It's too breaking to turn it on in the compiler by default.

Copy link
Contributor

@KevinRansom KevinRansom left a 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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@saul
Copy link
Contributor

saul commented Aug 31, 2017

@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.

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@dsyme is the fix here 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.

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

We can put it in new project templates and enable it by default in the coreclr projects. It's too breaking to turn it on in the compiler by default.

I'm ok with that approach.

@saul
Copy link
Contributor

saul commented Aug 31, 2017

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?

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

I've

Still need to adjust the templates

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@saul For C#

  • no effect on debugging since they use the names of the implementation.
  • signature and implementation may not match, without warning, e.g. you get
A.M x = XX, y = YY
B.M x = XX, y = YY
B.M x = YY, y = XX

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

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@saul I can definitely see the case for also implementing an optional warning on overrides

@saul
Copy link
Contributor

saul commented Aug 31, 2017

I think I'm being blind but I can't fix the codefix in this PR?

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@saul Yes, missed a file - now added

Copy link
Contributor

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 ``

Copy link
Contributor Author

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

Copy link
Contributor

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 '?

Copy link
Contributor

@saul saul Aug 31, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saul Thanks

Copy link
Contributor Author

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

@saul
Copy link
Contributor

saul commented Aug 31, 2017

Cheers Don. Looks like we're also missing the FSharp.Editor.fsproj change, too?

@dsyme dsyme changed the title [WIP] warning for mismatched param names warning for mismatched param names Aug 31, 2017
@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

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?

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

Cheers Don. Looks like we're also missing the FSharp.Editor.fsproj change, too?

@saul See https://github.com/Microsoft/visualfsharp/pull/3527/files#diff-2c15e8a33254afafc0e96c4f069e0aadR96

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@saul Thanks for the feedback so far. If you could give it a go that would be great

Copy link
Contributor

@saul saul left a 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.

@KevinRansom
Copy link
Contributor

@dsyme for coreclr put it in here: https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/FSharp.Build/Microsoft.FSharp.NetSdk.props
@dsyme lose the template changes, and create an issue to add it and assign it to me. I will add it in.

@dsyme
Copy link
Contributor Author

dsyme commented Aug 31, 2017

@dotnet-bot test Windows_NT Release_ci_part1 Build please

Copy link
Contributor

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.

Copy link
Contributor Author

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

@dsyme
Copy link
Contributor Author

dsyme commented Sep 1, 2017

@KevinRansom This is ready - when you merge can you create the tracking issue for templates? Thanks

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants