-
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
Warn when obj is inferred #13298
Warn when obj is inferred #13298
Conversation
This incorporates the motivating examples from fsharp/fslang-suggestions#885 .
@dsyme Do you have any opinions on the treatment of |
It's this sort of thing that is background to why we don't warn by default for this condition. I'm not sure what would be the best solution - it's perfectly reasonable to infer The opt-in warning is still likely to be useful in some scenarios so I'm OK with it, but I have no clear idea how often it would trigger in the scenarios where people really care about this. |
Would you prefer me to go through the F# compiler and get it free of this warning? There will be some noise with e.g. |
@Smaug123 No, we don't need to worry about this warning in the compiler, thanks |
@dsyme Would you mind please taking a look at the diff of 97ffb68 and letting me know whether this is a path I should pursue? It does work as a way of giving better type information rather than just This also uncovered what could be latent bugs in the tests, in that any error with
|
Will this warn on any inference of obj? I mean on parameters, locals etc? I'm really interested in warning that indicates that "obj" was inferred as type argument of some function call but not really with locals/parameters. Like: // obj is a perfectly okay fit here from a type sense but it's a high chance bug
JsonSerializer.Deserialize(someString) |> someGenericFunction |
I'm reasonably happy with this - running against the compiler shows a few oddities listed above, but not all that many. |
tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs
Outdated
Show resolved
Hide resolved
tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs
Outdated
Show resolved
Hide resolved
I think this is ready to go. (@nojaf or @safesparrow, how easy would it be for us to make a custom build of this compiler within G-Research and see what it does to my team's monorepo?) |
Once the change is in a preview SDK, it can be trivially tested internally. We also built from source in the past, although not without custom modifications to allow for no internet access. |
Thanks - sounds like the easiest way to stress test on our code is just to merge and fix forward if necessary, then. |
@Smaug123 if this get's merged we could try a nightly dotnet 8 SDK to test this inside GR. |
Fixes fsharp/fslang-suggestions#696 .
Criteria I had at the start for the definition of done:
needs to be turned off whenDon't know how I could do that; sounds like one for a followup PR instead. I've got tests documenting that this is currently not done.null
is used explicitly, on the grounds thatnull
is pretty clearly an obj.ditto but forditto, there are tests documenting that this is not donetypedefof
null
is flagged as being an objobj
; my cursory testing just now hasn't thrown that up, but I must have been thinking of something!)D:\a\_work\1\s\src\Compiler\unknown(1,1): error FS3524: A type…
This is essentially done as of Add fallback range to more typars #15301 ; there's still a case (probably in illib.fs) where a range is its default value, but I was unable to track it down, and it seems very rare.Status of PR: I think this is good to go. When compiling the compiler, the errors have essentially all been explicit uses of
null
, the underscore in atypedefof<_>
, or (rarely) somewhere likestatic member inline Make (f: obj -> string) = ValueConverter(box (f: obj -> string))
which for some reason requiredf
to be annotated on the right-hand side. There is still at least one place, probably in illib.fs, where we have a type parameter with no range (so we just get the useless diagnostic "unknown(1,1)").