-
Notifications
You must be signed in to change notification settings - Fork 790
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
Further enhancements to nameof #8754
Conversation
@Tarmil Will you be updating this? |
Yeah I'll get back to this soon, hopefully the conflict shouldn't be too hard to resolve. |
I've merged master into this. I'll likely integrate the changes into a final PR for nameof |
This is now ready - it now contains all the design adjustments for nameof
|
Error on neg16.fs:
|
@KevinRansom @cartermp this is ready |
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.
This is missing test cases for patterns - at a minimum, the example from fsharp/fslang-suggestions#841 should be used
thanks, will add those now |
From the original post by @Tarmil here I noticed two unchecked items that I didn't see in the commits, are these tracked/added elsewhere or already part of this PR? Namely, syntax coloring and code completion. |
Same failure - I feel like it should either be deleted or moved to non-FSharpQA since there's no diagnostics on why it failed |
@cartermp I agree Tbh I've confirmed the case by hand, I think we can deal with this separately. So as far as I'm concerned this is now ready |
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 can see where #7416 is resolved in the code. Is there a way to verify #8661 in tests at all? I guess it's tricky since everything has the same name in source, so it's a name resolution test and not an integration test. I don't quite understand name resolution enough to see how that gets resolved. But the test coverage here is adequate for the scenario so I'd like to get this in for people to use in the next round of previews.
let resolvedToModuleOrNamespaceName = | ||
if delayed.IsEmpty then | ||
let id,rest = List.headAndTail longId | ||
match ResolveLongIndentAsModuleOrNamespaceOrStaticClass cenv.tcSink ResultCollectionSettings.AllResults cenv.amap m false true OpenQualified env.eNameResEnv ad id rest true with |
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.
Note that with open type declarations coming in this call may no longer do what is assumed, see here: https://github.com/dotnet/fsharp/pull/9513/files#diff-dbb9e59b8ac1e1e04e1b00282a91ec97R2192
Does that have any impact? I would expect not...
I'm going to be looking at this today. |
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.
Instead of having nameof
be a special case in name resolution, couldn't we just add an Obsolete
attribute with this message?:
[<Obsolete("'nameof' is not supported in this version of your compiler.")>]
let nameof<'T> = ..
This will prevent older compilers from calling it.
Newer compilers will ignore the Obsolete attribute. When it detects it's using an older language version, just throw an error saying it's not supported in this version, use tryLanguageFeatureErrorRecover
from ErrorLogger
to perform the check and raise the error.
It feels a bit icky to have nameof
be a special case in name resolution. Ultimately, we just want an error at the end of the day.
nameof has existed in FSharp.Core for over a year, so deprecating it will not reliably work. :-( |
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.
Thanks for this work.
Kevin
|
@KevinRansom shouldn't
|
The experimental attribute is only while things are in preview. Since we are moving nameof to F# 5 (which is still in preview, so no guarantees about current behavior as-shipped yet), that attribute was removed. We're also removing it for most other things now that we're nearing the end of the development cycle. |
The current experience today is that you can still call |
I am trialling this, it should do the trick for giving a reasonable message to old compilers a25541a |
If this doesn't give the result we need then we can forget it I think |
THis is ready to go |
@dsyme , attributes on nameof are not going to be particularly helpful, because the method has already shipped in fsharp.core.dll since I think 4.7.0. I suppose it would help, when trying to build an updated fsharp.core, however, it would be a breaking change due to the fact it's already shipped. Even though a successful build against an old library is merely a runtime error. |
I'm fine with the outcome of this. I think in practice people aren't going to really be hit by this though. |
Yes, I think adding the attribute is best regarded as a good bug fix. |
Certainly there is no harm doing so. |
Let's merge this baby and enable this in 5.0 |
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.
Changes look good. Thank you @Tarmil for kick-starting the enhancements.
I think this is now ready.
* Implement `nameof x` as a constant pattern * Resolve ident to find `nameof` in patterns * fix build * fix build * re-enable tests * fix test * fix operators * align code * test and fix pattern matching * fix 8661, 7416 * fix tests and error messages * 'fix test' * 'fix test' * add message for C# and old compilers * fix build * suppress error 3501 when a compiler supports nameof Co-authored-by: Don Syme <dsyme@microsoft.com>
* Implement `nameof x` as a constant pattern * Resolve ident to find `nameof` in patterns * fix build * fix build * re-enable tests * fix test * fix operators * align code * test and fix pattern matching * fix 8661, 7416 * fix tests and error messages * 'fix test' * 'fix test' * add message for C# and old compilers * fix build * suppress error 3501 when a compiler supports nameof Co-authored-by: Don Syme <dsyme@microsoft.com>
Feature suggestion: https://github.com/fsharp/fslang-design/blob/master/FSharp-5.0/FS-1085-nameof-pattern.md