-
Notifications
You must be signed in to change notification settings - Fork 789
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
Compiler does not infer string type for nameof pattern #13377
Comments
@dsyme this is indeed producing invalid IL, hit it today as well. |
Thanks, should be a simple fix |
@vzarytovskii this is a good first issue, happy to guide the fix |
I have also hit this . Happy to help fixing this with a little bit of guidance as I’m still new to the compiler . cc @dsyme |
I looked a bit into this and to me it seems that the issue to be in |
Hey, @ntovas, I'm on vacation currently, without acces to my laptop unfortunately :( Perhaps someone from the team can chime in, and help you looking into it? @dotnet/fsharp-team-msft ping! |
@ntovas : This is the approach I would take: Before starting it, sprinkle breakpoints around code in the TypeChecking state, so that you can step the execution and investigate the available parameters. One of the places that seems to be related is \src\Compiler*Checking**CheckPatterns*.fs . I would try to put a few breakpoints into that and trace it - e.g. to verify that the nameof is infered to be a constant expression, and also explicitely marked as constant expression of string type. All nameof-related functionality is a behind a feature flag, which can also give you an idea at which places the compiler interacts with this feature: |
I would also add that |
Hey @T-Gro , |
On it :) |
When using
nameof
in a pattern match, I'd expect the compiler to infer the argument type asstring
sincenameof
returns astring
. However, the argument is treated as generic and generates invalid IL.Repro steps
According to the RFC for the nameof pattern feature, the
nameof expr
should be "equivalent to a literal string pattern" which is not being respected.Expected behavior
Expect the compiler to infer argument type as
string
whennameof
is used in a pattern match.Actual behavior
Compiler infers argument type as generic argument when
nameof
is used in a pattern match.Known workarounds
Explicit type annotation.
The text was updated successfully, but these errors were encountered: