Open Ilir-Liburn opened 5 years ago
Why would it call toInt()
?
Instead it should throw an error, because (intValue:Above<Int>)
inside of fromInt()
means a recursive cast. @Simn ?
Looks like it yeah... the more errors these multitype abstracts throw the better.
@RealyUniqueName, yes in the case of regular abstract, but multitype abstract is constructed from @:to, not @:from, right? That is why I proposed to unify them
abstract MyMap<K, V>(IMap<K, V>) {
public function new();
@:from inline function fromInt<K:Int>() this = new IntMap<V>();
@:from inline function fromString<K:String>() this = new StringMap<V>();
@:to function toIntMap():IntMap<V> return cast this;
@:to function toStringMap():StringMap<V> return cast this;
@:to function toInterface():IMap<K, V> return this;
}
where
but @Simn have something other on his mind: "The abstract still has to know all of its specializations, and inline functions cause the abstract type to disappear."
I still think that it shouldn't call toInt()
. E.g. std Map
doesn't invoke additional implicit casting inside of @:from
functions.
Whatever you decide, it's fine with me. My goal is discussion of different aspects for abstract types because I think that's the most important and most powerful part of the Haxe for the end user like me. Until abstract type reaches its final design.
Since @Simn already rejected that idea in #8743 let's focus on recursive implicit cast here. We need to change it to emit an error just like in normal abstracts.
Please note that fixing (v:Above\<Int>) will change nothing. I can do following
@:from static inline function fromInt(v:Int) return cast {value:v, type:TInt};
@:from static inline function fromFloat(v:Float) return null;
and result is
a1 = ((object) (1) );
a2 = ((object) (1.1) );
Multitype abstract is always casting argument, no matter what is returned.
Shouldn't (v:Above\<Int>) at fromInt call toInt in above example? Instead, a1 = 1 makes a1 an object, casting 1 to object, being not inlined like a2