Skip to content
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

FS0049 isn't reported for short names #17878

Closed
auduchinok opened this issue Oct 13, 2024 · 8 comments
Closed

FS0049 isn't reported for short names #17878

auduchinok opened this issue Oct 13, 2024 · 8 comments
Labels
Area-Compiler Compiler-related issues which don't belong to other categories Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@auduchinok
Copy link
Member

There's a warning reported for this code, saying that it may intent to use non-imported symbol, but defines a new local value instead:

match 1 with
| One -> ()

It's, however, not reported for shorter names, which may be the case for various literals, union cases, or active patterns:

match 1 with
| On -> ()
@auduchinok
Copy link
Member Author

This is the problematic code:

&& id.idText.Length >= 3

If there's no objections, I'd like to remove this check.

@edgarfgp
Copy link
Contributor

edgarfgp commented Oct 13, 2024

It is a very very very unfortunate historical hack that seems to related the use country and language codes, which are very common in codebases

Removing this check will cause a lot of new warnings/errors in existing codebases.

I did some investigation here https://github.com/dotnet/fsharp/pull/15816/files

@edgarfgp
Copy link
Contributor

I think we should remove this check in the next mayor version and explain the reasoning.

  • Users that have this ignored wont notice the difference
  • Users with TreatWarningsAsError will have the option to ignore it

@vzarytovskii
Copy link
Member

I think we should remove this check in the next mayor version and explain the reasoning.

* Users that have this ignored wont notice the difference

* Users with `TreatWarningsAsError` will have the option to ignore it

I still think it's a huge breaking change, before we do it, we need to assess how much code there's in the nuget libraries/github code.

@edgarfgp
Copy link
Contributor

I still think it's a huge breaking change, before we do it, we need to assess how much code there's in the nuget libraries/github code.

Agreed that this is a breaking change. Not sure about the "huge" part. IMO we have done more severe ones like the AttributeTargets or even requiring seq every where will be more impacting for users.

The compiler should have never check for country codes(US etc). If someone wants this they can use/write an analyser.

@auduchinok
Copy link
Member Author

auduchinok commented Oct 17, 2024

I still think it's a huge breaking change, before we do it, we need to assess how much code there's in the nuget libraries/github code.

It's worth noting that this warning isn't produced for bindings, so it shouldn't affect symbols exported from libraries. Consider this module:

let Aaa = ()

match () with
| Bbb -> ()

There's no warning for Aaa, only for Bbb, and Bbb isn't exported anywhere, it's a local value.

Let's consider another case with local values:

match f () with
| Us -> ()
| Uk -> ()
...

In this case Us should either resolve to some union case, literal, or active pattern, or there's a chance it's a mistake due to the needed symbol isn't imported. The warning would help here a lot. In addition to that, there can't be several names in different branches which could all match, because the Us pattern makes Uk and others never match.

We can also adjust the shouldWarn check for other cases like this if we want to keep the warning in some cases:

let f Us Uk = ...

@psfinaki
Copy link
Member

@edgarfgp just to make sure, has your change here also addressed this ticket?

@psfinaki psfinaki added Area-Compiler Compiler-related issues which don't belong to other categories Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage labels Nov 18, 2024
@edgarfgp
Copy link
Contributor

@psfinaki Yes. we now report pattern(any length) in a match cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler Compiler-related issues which don't belong to other categories Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

No branches or pull requests

4 participants