-
Notifications
You must be signed in to change notification settings - Fork 772
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
Support constraint intersection syntax #15413
Conversation
Probably needs a small addition to rfc/new small rfc, so behaviour is documented. |
@kerams will it make possible to intersect generic and non-generic restrictions? E.g. let test (env: 'T & #IDisposable & #ILogger<'T>) =
() |
Yes, but unless I am misunderstanding something, your constraints are not satisfiable. This appears to be doable: let test (env: 't & #seq<'u> & #Collections.IEnumerable) =
()
test [ [ 1 ] ] |
I think it can, the whole Generic Maths feature is build atop of |
tests/FSharp.Compiler.ComponentTests/Language/ConstraintIntersectionTests.fs
Show resolved
Hide resolved
@Lanayx, you're right. I don't quite understand how, but this works: let test (env: 't & #System.Numerics.INumber<'t> & #IEquatable<'t>) =
()
let test2 (env: 't when 't :> #System.Numerics.INumber<'t> and 't :> IEquatable<'t>) =
()
test 1
test2 1 |
Yeah, that's pretty much due to changes we introduced for static abstracts in interfaces. At least I believe so. |
That's great! In that case it will subsume the old syntax (which I didn't like anyway), e.g. instead of let test (env: 'T when INumber<'T>) =
() we'll be able to write let test (env: 'T & #INumber<'T>) =
() |
Why do you think constraints are not solvable? It's just an interface like for example INumber'TSelf which works via implementing an interface of itself. |
Implements fsharp/fslang-suggestions#1262.
The parser changes could quite possibly be improved - it's not my forte.
RE: fsharp/fslang-suggestions#1262 (comment)
Elsewhere in the code, there's this check:
Not sure why this should only kick in for
NoNewTypars
. InTcIntersectionConstraint
new typars seemed to always be OK, so such check would have no effect. However, currently we get this, which should be sufficient anyway: