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

Type parameter broken in multiType abstract #10123

Closed
kevinresol opened this issue Feb 18, 2021 · 2 comments
Closed

Type parameter broken in multiType abstract #10123

kevinresol opened this issue Feb 18, 2021 · 2 comments

Comments

@kevinresol
Copy link
Contributor

4.1.5 prints Warning : Bool
4.2.0 prints Warning : Unknown<0>

comment out the @:to will make it print Bool again

class Main {
	static function main() {
		var c:Collection<Int, Bool> = null;
		$type(c.item); 
	}
}

@:forward
@:multiType(@:followWithAbstracts K)
abstract Collection<K, Item>(ICollection<K, Item>) from ICollection<K, Item> {
	public function new();
	@:to inline function toIntCollection<K:Int, Item>():IntCollection<Item>
		return new IntCollection<Item>();
}

interface ICollection<K, Item> {
	var item:Item;
}

class IntCollection<Item> implements ICollection<Int, Item> {
	public var item:Item;
	public function new() {}
}
@Simn
Copy link
Member

Simn commented Feb 18, 2021

This might actually be about @:forward:

class Main {
	static function main() {
		var c:Collection<Int, Bool> = null;
		$type(c.get().item); // Bool
		$type(c.item); // Unknown<0>
	}
}

@:forward
@:multiType
abstract Collection<K, Item>(ICollection<Item>) {
	public function new();

	@:to function toIntCollection<K:Int, Item>():ICollection<Item> {
		return null;
	}

	public function get() {
		return this;
	}
}

interface ICollection<Item> {
	var item:Item;
}

@RealyUniqueName
Copy link
Member

Actually, it works better since Haxe 4.2
You're introducing new type params on an instance field instead of using type params of the abstract. That's why they become unbound monomorphs.
To fix that you need to change the code in one of the following ways:

@:to static function toIntCollection<K:Int,V>(t:ICollection<V>):ICollection<V> {
	return null;
}
@:to function toIntCollection():ICollection<V> {
	return null;
}

kevinresol added a commit to kevinresol/coconut.ds that referenced this issue Mar 16, 2021
kevinresol added a commit to kevinresol/coconut.ds that referenced this issue Mar 16, 2021
@RealyUniqueName RealyUniqueName modified the milestones: Hotfix, Bugs Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants