Cannot infer method type argument when using an implicit cast #2067
Unanswered
gafter
asked this question in
Language Ideas
Replies: 2 comments
-
trying to understand the issue here, I think the compiler tries to run overload resolution on |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ran into this issue with Array -> Span using System;
static class Program
{
static void Main()
{
int[] values = default;
// no implicit conversion
MethodA(values); // <- works
// implicit conversion
MethodB<int>(values); // <- works
MethodB(values.AsSpan()); // <- works
MethodB(values); // <- does not work (but could work if type inferencing accounted for implicit casting operators)
}
static void MethodA<T>(T[] a) { }
static void MethodB<T>(Span<T> a) { }
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@RunDevelopment commented on Thu Jun 07 2018
Version Used:
C# 7.3
Steps to Reproduce:
Consider the following example:
Now, let's try to call
Consume
:Expected Behavior:
The type
int
is inferred and an implicit cast is performed.Actual Behavior:
The type is not inferred.
CS0411: The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.
Additional thoughts
Despite that, the following works just fine.
@jcouv commented on Sun Jun 10 2018
I believe this follows current language design, but I'll check in the spec.
Completed example:
@gafter commented on Tue Dec 11 2018
This is a type inference language feature request. Moving to
csharplang
.Beta Was this translation helpful? Give feedback.
All reactions