Uh oh!
There was an error while loading. Please reload this page.
[RFC FS-1093] Additional type directed conversions - #10884
Conversation
dsyme
commented
Jan 16, 2021
Test failures (all expected, at a first glance) |
charlesroddie
commented
Jan 16, 2021
This would implement fsharp/fslang-suggestions#849 |
dsyme
commented
Jan 19, 2021
I set up auto-flow from |
dsyme
commented
Jan 21, 2021
* [main] Update dependencies from dotnet/arcade (#10913) Microsoft.DotNet.Arcade.Sdk From Version 6.0.0-beta.21068.2 -> To Version 6.0.0-beta.21069.2 Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com> * Refactor everything but the type provider tests in signature help testing (#10908) Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Phillip Carter <pcarter@fastmail.com>
Testing this branch along with anonymous union. typeDU= DU ofintlet_:obj = DU(0)//error FS0001: This expression was expected to have type ...typeR={ a:int }let_:obj ={ a =0}//error FS0001: This expression was expected to have type ...let_:obj ={|a=1|}// works[<Measure>]typeidtypeUserId= int<id>letid:UserId =0<id>let_:obj = id // worksEdit: just noticed your notes on record which is todo😛 |
Happypig375
commented
Jul 26, 2021
But we can still disable automatic upcasting at override returns (and go on the error path before this PR) and emit a covariant return instead? |
Like type[<AbstractClass>]A()=abstractA:unit->objtypeB()=
inherits A()overrideA()=()// Covariant returntypeC()=
inherits A()overrideA()= Unchecked.defaultof<_>// Infer obj since type inference kicks in and no other type is knowntypeD()=
inherits A()overrideA()=():>_// Infer obj type for type hole |
dsyme
commented
Jul 26, 2021
I don't think so, because existing code already relies on the eager application of the non-covariant type information. To be honest, co-variant returns are just unlikely to ever make it into F#. Remember F# strongly biases against class/interface hierarchies as a modelling technique (though this stuff does have its uses). If we ever add them, I'm pretty certain we would want strong type information for updated types for the slots. |
dsyme
commented
Jul 26, 2021
@KevinRansom This is now ready for preview. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
KevinRansom
commented
Aug 9, 2021
I'll fix the test issues |
merge main and Fix tests for auto widen
dsyme
commented
Aug 10, 2021
@KevinRansom thanks! |
dsyme
commented
Aug 10, 2021
@KevinRansom all ready I think |
Implementation of RFC https://github.com/fsharp/fslang-design/blob/master/FSharp-6.0/FS-1093-additional-conversions.md
This primarily loosens the auto-widening rules in the presence of explicit type annotations or other "known" type information, e.g. to allow things like:
It also adds
int32 --> int64conversions and a limited form ofop_Implicitsupport.In this PR the rule is:
When processing an expression the "overall type" is usually labelled as "MustConvertTo" the known type, instead of "MustEqual"
This is propagated over if/then/else and other control structures. So if
if then A then Bmust convert to T, then both A and B must convert to T, but A and B may have different types.For leaf expressions, we often have immediate knowledge of both the source and MustConvertTo types. If a unification between the two would have failed then subsumption and adhoc conversions can be tried instead.
The adhoc conversions enabled are in the RFC.
This also allows (the removal of upcast coercions like
asExpron this line](https://github.com/dotnet/fsharp/blob/main/src/fsharp/FSharp.Core/Linq.fs#L282), e.g. in favour of one explicit type annotation.A longer list of things enabled is below and in the RFC