Skip to content
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

Semantics of different abstract implict cast kinds are not the same #444

Open
Gama11 opened this issue Dec 26, 2019 · 0 comments
Open

Semantics of different abstract implict cast kinds are not the same #444

Gama11 opened this issue Dec 26, 2019 · 0 comments

Comments

@Gama11
Copy link
Member

Gama11 commented Dec 26, 2019

https://haxe.org/manual/types-abstract-implicit-casts.html claims that to and @:to should be identical in behavior:

Class field casts have the same semantics, but are defined completely differently:

In practice this doesn't seem to be the case:

import haxe.ds.HashMap;

class Main {
	static function main() {
		var map1 = new HashMap<Hashable1, Bool>(); // works
		var map2 = new HashMap<Hashable2, Bool>(); // constraint check failure
	}
}

abstract Hashable1(HashableImpl) to {function hashCode():Int;} {}

abstract Hashable2(HashableImpl) {
	@:to function toHashCode():{function hashCode():Int;} {
		return this;
	}
}

class HashableImpl {
	public function new() {}

	public function hashCode():Int {
		return 0;
	}
}

@RealyUniqueName says this is by design, and thus should be documented accordingly. Would be helpful to have a list of situations where @:to and @:from are not considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant