-
Notifications
You must be signed in to change notification settings - Fork 53
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
Iconsistent type alias compatibility behavior. #360
Comments
Technically, this behavior is correct:
I think, Rule 1 should remain in effect, as I don't want to require as many explicit casts as Go does. Should we relax Rule 2 to make A. Compatibility is a property that is just checked, rather than enforced by some implicit casts. Casting a dynamic array at runtime is a highly nontrivial procedure. I thought it should be visible to the user, so I only allowed it as an explicit cast. B. Should |
IMO we shouldn't have []int8 and []uint16 et al compatible, the reason is that []alias1 and []alias2 are actually trivially compatible, since they're technically the same type. Do we need this non-equivalence in type assignments? Feels inconsistent to me. |
What you mean here is that
Are |
I think they're not the same, since they're not the same actual base type. So there's 2 real options in my opinion:
Base types are not equivalent to each other, alias types are equivalent as long as their base type is equivalent. Having type assignments be base types will break a lot of things, as we discussed in #337. Having them be compatible types seems too complicated in my opinion, so more logical thing for them is to be aliases. |
@skejeton And thus you end up with a contradiction.
So
So How is that possible? What's the difference between P.S. I assume that you're using the term "base type" in a meaning different from the Umka reference. For you, it means a "distinct type" or "something that is not an alias", rather than a base type of a pointer or an array. |
To outline the concepts:
Rect and Ellipse examples create distinct base types because they're created with The algorithm for type compatibility:
Base types are not compatible
The comparison is the same, just before checking type compatibility, alias types should "unwrap" the base types that they point to, and check if they're the same type. |
@skejeton Are |
No: |
@skejeton Both
Do I understand your vision correctly? |
Pretty much yes, I see
|
@skejeton Now I understand you. Which doesn't mean I share the same view.
|
Wait, how does |
@skejeton In general, Umka uses structural type equivalence, i.e., two types are equivalent iff they have the same layout, field/parameter names, etc. So the type name doesn't really matter. However, there are two exceptions where Umka relies on nominal type equivalence instead:
|
If |
My take on this situation: There are two relations types can have:
Equivalent:
Compatible:
Arrays and maps will just inherit the properties of their base types. |
Because all integer types are compatible even if they are not equivalent ( |
I see it now. I think I agree with Marek's opinion in here, the only thing I'm not entirely sure about is whether having different aliases based on the same type be compatible or equivalent. Choosing this would change whether in the original example we need to explicitly cast alias1 to alias2 or not. |
@marekmaskarinec I need to think more about it, but here is what seems doubtful to me for now:
|
This is allowed:
This is not allowed:
This is related to #340, but I think it's a different issue because the former needs to include the module name in the type names.
The text was updated successfully, but these errors were encountered: