-
Notifications
You must be signed in to change notification settings - Fork 1
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
Order of implicit MapOf.New constructors leads to inconsistent behaviour #521
Comments
@fneu I believe there must be a misobservation of some kind. var map =
MapOf.New(
KvpOf.New(0, "zero"),
KvpOf.New(1, "one"),
KvpOf.New(2, "two")
); It cannot be the case that this code points to the ctor /// <summary>
/// A map from the given KeyValuePairs
/// </summary>
public static IDictionary<Key, Value> New<Key, Value>(KeyValuePair<Key, Value> item, params KeyValuePair<Key, Value>[] more)
=> new MapOf<Key, Value>(item, more); KvpOf is of type IKvp, while the constructor you mention accepts KeyValuePair<,>. There is no implicit conversion present for IKvp<,> - so I guess there must be some confusion about the types. How did you find the mentioned constructor? When I do a "go to reference" for your Map.New code, it takes me to: |
@Meerownymous hope you're doing well :) It seems that you're right and it uses IKvp. However, the problem is still the same. The problematic case is the one with 4 arguments:
Meanwhile, the case with 3 arguments behaves as expected: |
Yes thanks, all good. Hope you too. Now I could reproduce. C# defines rules about how to decide for a method if it has ambiguity, so it may be solvable by studying them. I found this snippet:
So if I git it right - one solution is to change KvpOf.New to return KvpOf instead of IKvp, and offer a Map.New method accepting KvpOf (not IKvp) - with matching parameter count for every Map.New method that accepts alternating Key, Value paremeters. Other possibility is to remove the params MapOf.New constructor. Workaround in this version is to explicitely define the generics or not use Kvps but the shorthand constructors with the alternating Key, Value parameters. You might find other ways too. |
Expected Behavior
Inferred type of generic maps does not depend on the number of Kvps passed to
MapOf.New()
constructorsActual Behavior
This map, like any map with an odd number of Kvp arguments:
uses this constructor:
Yaapii.Atoms/src/Yaapii.Atoms/Map/MapOf.cs
Lines 1062 to 1066 in db89948
and is consequently of type
Yaapii.Atoms.Map.MapOf<int, string>
.In contrast, this map, like any map with an even number of Kvp arguments:
appears to use this constructor (or an equivalent for the number of arguments):
Yaapii.Atoms/src/Yaapii.Atoms/Map/MapOf.cs
Lines 672 to 682 in db89948
and is consequently of type
Yaapii.Atoms.Map.MapOf<Yaapii.Atoms.IKvp<int, string>, Yaapii.Atoms.IKvp<int, string>>
Mention any other details that might be useful
present in Yaapii.Atoms 2.7.2
The text was updated successfully, but these errors were encountered: