-
Notifications
You must be signed in to change notification settings - Fork 783
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
Using multiple operators in INumber-constrained generic functions leads to compiler error #17062
Comments
Note: Works fine when chaining |
For reference — these tests should be extended to cover this: Lines 1 to 33 in 273cea5
|
Yes, as in let numericOpsPlus<'T when INumber<'T>> (num: 'T) =
num
|> fun num' -> 'T.(+) (num, num')
|> fun num' -> 'T.(+) (num, num') or let numericOpsPlus<'T when INumber<'T>> (num: 'T) =
num
|> fun num' -> 'T.op_Addition (num, num')
|> fun num' -> 'T.op_Addition (num, num') or let numericOpsPlus<'T when INumber<'T>> (num: 'T) =
let (+) x y = 'T.(+) (x, y)
num + num + num |
Yes, also: open System.Numerics
let numericOpsPlusPlus<'T when INumber<'T>>(num: 'T) =
((num + num) : 'T) + num and open System.Numerics
let numericOpsPlusPlus<'T when INumber<'T>>(num: 'T) =
'T.op_Addition('T.op_Addition(num, num), num) |
We suffer flexibility of the |
This might show where the problem is: something is probably getting confused when looking at the multiple type parameters in |
It's probably only in conjunction with + (might be others too). |
@brianrourkeboll regarding the above, since it's constrained via INumber, I would expect it to have all typars to be unified. |
It does for the other Interestingly, this does not trigger the problem: open System.Numerics
#nowarn "3535"
type IFace<'a, 'b, 'c> =
static abstract (>*..*<) : 'a * 'b -> 'c
let customOps<'T when IFace<'T, 'T, 'T>> (num: 'T) =
num >*..*< num >*..*< num
type T =
| T of int
interface IFace<T, T, T> with
static member (>*..*<) (T a, T b) = T (a + b)
customOps (T 1) |
Yeah, many of the "standard" operators have somewhat special treatment. |
By the way, this is how I found this bug: m4rs-mt/ILGPU#463 (comment) I've been playing with F# and ILGpu and so far it feels quite nice. |
When using inline, code does compile to public static T numericOpsPlus<T>(T num) where T : INumber<T>
{
T val = num + num;
return val + num;
} |
Please provide a succinct description of the issue.
The text was updated successfully, but these errors were encountered: