haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Invalid "is" operator

Open ncannasse opened this issue 1 year ago • 2 comments

The following should fail at compile time :

"" is Int

isoperator should only compile is there is a possibility for it to be true.

ncannasse avatar Mar 21 '25 11:03 ncannasse

That looks like warning territory, mostly because I can imagine scenarios where a macro might generate this kind of expression. By using a warning, we give the user the option to disable it.

To be clear, are you suggesting that we do a unify rhs lhs check for all such cases?

Simn avatar Mar 21 '25 12:03 Simn

There are some controversies here in the context of abstracts. Consider this:

import haxe.ds.StringMap;

function main() {
	var someMap:Map<String, Int>;
	trace(someMap is StringMap);
}

Assigning StringMap<?> to Map<String, ?> is generally not permitted (that is, unification fails) because it relies on the expression-level @:from static inline function fromStringMap<V> on Map being inserted via cast_or_unify. This is not something we can do here though because we don't really have an rhs expression that is typed as StringMap.

Simn avatar Apr 11 '25 07:04 Simn